Skip to content

Commit

Permalink
clean up deprecated attributes in test, minor type improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
seemk committed Oct 17, 2024
1 parent 5af79ea commit 261683a
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 25 deletions.
16 changes: 7 additions & 9 deletions test/metrics.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ import {
MetricData,
View,
} from '@opentelemetry/sdk-metrics';
import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';
import { ATTR_DEPLOYMENT_ENVIRONMENT } from '@opentelemetry/semantic-conventions/incubating';
import { ATTR_SERVICE_NAME } from '@opentelemetry/semantic-conventions';

import { hrtime } from 'process';
import { parseOptionsAndConfigureInstrumentations } from '../src/instrumentations';
import { _setDefaultOptions, startMetrics } from '../src/metrics';
import { cleanEnvironment, TestMetricReader } from './utils';
import { strict as assert } from 'assert';
import { describe, it, after, beforeEach } from 'node:test';
import { inspect } from 'util';

function emptyCounter() {
return {
Expand Down Expand Up @@ -110,7 +110,7 @@ describe('metrics', () => {
assert.deepEqual(options.accessToken, '');
assert.deepEqual(options.exportIntervalMillis, 30000);
assert.deepEqual(
options.resource.attributes[SemanticResourceAttributes.SERVICE_NAME],
options.resource.attributes[ATTR_SERVICE_NAME],
'@splunk/otel'
);
assert.deepEqual(options.runtimeMetricsEnabled, true);
Expand Down Expand Up @@ -139,7 +139,7 @@ describe('metrics', () => {
assert.deepEqual(options.resource.attributes['key1'], 'val1');
assert.deepEqual(options.resource.attributes['key2'], 'val2');
assert.deepEqual(
options.resource.attributes[SemanticResourceAttributes.SERVICE_NAME],
options.resource.attributes[ATTR_SERVICE_NAME],
'bigmetric'
);
assert.deepEqual(options.runtimeMetricsEnabled, true);
Expand All @@ -161,7 +161,7 @@ describe('metrics', () => {
// Custom metrics and runtime metrics are done with 1 test as OTel meter provider can't be reset
it('is possible to use metrics', async () => {
const resource = new Resource({
[SemanticResourceAttributes.DEPLOYMENT_ENVIRONMENT]: 'test',
[ATTR_DEPLOYMENT_ENVIRONMENT]: 'test',
});
const { metricsOptions } = parseOptionsAndConfigureInstrumentations({
metrics: {
Expand Down Expand Up @@ -191,15 +191,13 @@ describe('metrics', () => {

assert.deepEqual(
metricData.resourceMetrics.resource.attributes[
SemanticResourceAttributes.DEPLOYMENT_ENVIRONMENT
ATTR_DEPLOYMENT_ENVIRONMENT
],
'test'
);

assert.deepEqual(
metricData.resourceMetrics.resource.attributes[
SemanticResourceAttributes.SERVICE_NAME
],
metricData.resourceMetrics.resource.attributes[ATTR_SERVICE_NAME],
'foo'
);

Expand Down
3 changes: 1 addition & 2 deletions test/options.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ describe('options', () => {
});

describe('defaults', () => {
// const sandbox = sinon.createSandbox();
let instrMock;
beforeEach(() => {
// Mock the default `getInstrumentations` in case some instrumentations (e.g. http) are part of dev dependencies.
Expand Down Expand Up @@ -525,6 +524,6 @@ function testSpanProcessorFactory(options: Options) {
return new SimpleSpanProcessor(exporters);
}

function testPropagatorFactory(options: Options): api.TextMapPropagator {
function testPropagatorFactory(_options: Options): api.TextMapPropagator {
return new W3CBaggagePropagator();
}
15 changes: 8 additions & 7 deletions test/profiling/profiling.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@ import { inspect } from 'util';
import { context, trace } from '@opentelemetry/api';
import { Resource } from '@opentelemetry/resources';
import { InMemorySpanExporter } from '@opentelemetry/sdk-trace-base';
import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';
import { ATTR_SERVICE_NAME } from '@opentelemetry/semantic-conventions';

import { start, stop } from '../../src';
import {
_setDefaultOptions,
defaultExporterFactory,
} from '../../src/profiling';
import { ProfilingStacktrace } from '../../src/profiling/types';
import { ProfilingContextManager } from '../../src/profiling/ProfilingContextManager';
import {
CpuProfile,
Expand All @@ -50,11 +51,11 @@ describe('profiling', () => {

it('sets default options when no options are provided', async () => {
const options = _setDefaultOptions();
await options.resource.waitForAsyncAttributes();
await options.resource.waitForAsyncAttributes?.();
const testResource = new Resource({
[SemanticResourceAttributes.SERVICE_NAME]: '@splunk/otel',
[ATTR_SERVICE_NAME]: '@splunk/otel',
}).merge(detectResource());
await testResource.waitForAsyncAttributes();
await testResource.waitForAsyncAttributes?.();

const { resource: defaultResource, ...defaultOtherAttrs } = options;

Expand All @@ -69,8 +70,8 @@ describe('profiling', () => {
});

assert.deepStrictEqual(
defaultResource._attributes,
testResource._attributes
defaultResource.attributes,
testResource.attributes
);
});

Expand Down Expand Up @@ -104,7 +105,7 @@ describe('profiling', () => {
describe('startProfiling', () => {
it('exports stacktraces', async () => {
let sendCallCount = 0;
const stacktracesReceived = [];
const stacktracesReceived: ProfilingStacktrace[] = [];
const exporter: ProfilingExporter = {
send(cpuProfile: CpuProfile) {
const { stacktraces } = cpuProfile;
Expand Down
2 changes: 1 addition & 1 deletion test/service_name.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { defaultServiceName, findServiceName } from '../src/utils';

describe('findServiceName', () => {
const TMP_PREFIX = 'splunk-otel-service-name-test-';
let tempDir;
let tempDir: string;

beforeEach(() => {
tempDir = fs.mkdtempSync(path.join(os.tmpdir(), TMP_PREFIX));
Expand Down
3 changes: 1 addition & 2 deletions test/start.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import * as tracing from '../src/tracing';

import * as utils from './utils';

const CONFIG = {};
const CONFIG: Record<string, any> = {};

const accessToken = 'accessToken';
const endpoint = 'endpoint';
Expand Down Expand Up @@ -129,7 +129,6 @@ describe('start', () => {

afterEach(() => {
stop();
// sinon.restore(); //FIXME hmmm
});

describe('toggling signals', () => {
Expand Down
1 change: 1 addition & 0 deletions test/tracing/nextjsfix.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { NextJsSpanProcessor } from '../../src/tracing/NextJsSpanProcessor';
import { NodeTracerProvider } from '@opentelemetry/sdk-trace-node';
import { Resource } from '@opentelemetry/resources';
import { ATTR_SERVICE_NAME } from '@opentelemetry/semantic-conventions';
import { describe, it, afterEach } from 'node:test';

describe('Next.js span processor', () => {
const exporter = new InMemorySpanExporter();
Expand Down
8 changes: 4 additions & 4 deletions test/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import * as util from 'util';
import { Writable } from 'stream';
import { context, trace } from '@opentelemetry/api';

const isConfigVarEntry = (key) => {
const isConfigVarEntry = (key: string) => {
const lowercased = key.toLowerCase();
return (
lowercased.includes('splunk_') ||
Expand Down Expand Up @@ -109,8 +109,8 @@ export function assertInjection(
}
}

export function calledWithExactly(mocked, expected) {
const match = mocked.mock.calls.some((call) => {
export function calledWithExactly(mocked: any, expected: any) {
const match = mocked.mock.calls.some((call: any) => {
try {
assert.deepStrictEqual(call.arguments[0], expected);
return true;
Expand All @@ -122,7 +122,7 @@ export function calledWithExactly(mocked, expected) {
assert(match, `Expected call with: ${JSON.stringify(expected)} not found`);
}

export function calledOnceWithMatch(mocked, match: Object) {
export function calledOnceWithMatch(mocked: any, match: Object) {
assert.strictEqual(
mocked.mock.calls.length,
1,
Expand Down

0 comments on commit 261683a

Please sign in to comment.