Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to OpenTelemetry 1.18.1 / 0.45.1 #852

Merged
merged 5 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,352 changes: 676 additions & 676 deletions package-lock.json

Large diffs are not rendered by default.

94 changes: 47 additions & 47 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"lint": "eslint . --ext .ts",
"lint:commits": "commitlint",
"test": "npm run test:unit && npm run test:debug-metrics && npm run test:instrumentations",
"test:unit": "cross-env TEST_ALLOW_DOUBLE_START=y nyc ts-mocha --exclude 'test/instrumentation/external/**/*.test.ts' --exclude 'test/separate_process/*' --timeout 60s --parallel --jobs 2 -p tsconfig.json 'test/**/*.test.ts'",
"test:unit": "cross-env TEST_ALLOW_DOUBLE_START=y nyc ts-mocha --exclude 'test/instrumentation/external/**/*.test.ts' --exclude 'test/separate_process/*' --timeout 60s --parallel --jobs 4 -p tsconfig.json 'test/**/*.test.ts'",
"test:debug-metrics": "nyc --no-clean ts-mocha -p tsconfig.json 'test/separate_process/debug_metrics.test.ts'",
"test:instrumentations": "nyc ts-mocha --require test/instrumentation/external/setup.ts --jobs 1 'test/instrumentation/external/**/*.test.ts'",
"prebuild:current": "node scripts/prebuild-current.js",
Expand Down Expand Up @@ -104,54 +104,54 @@
"@grpc/grpc-js": "^1.8.19",
"@grpc/proto-loader": "^0.7.8",
"@opentelemetry/api": "^1.3.0",
"@opentelemetry/context-async-hooks": "1.17.1",
"@opentelemetry/core": "1.17.1",
"@opentelemetry/exporter-metrics-otlp-grpc": "0.44.0",
"@opentelemetry/exporter-metrics-otlp-proto": "0.44.0",
"@opentelemetry/exporter-trace-otlp-grpc": "0.44.0",
"@opentelemetry/exporter-trace-otlp-proto": "0.44.0",
"@opentelemetry/instrumentation": "0.44.0",
"@opentelemetry/instrumentation-amqplib": "0.33.2",
"@opentelemetry/instrumentation-aws-sdk": "0.36.1",
"@opentelemetry/instrumentation-bunyan": "0.32.2",
"@opentelemetry/instrumentation-cassandra-driver": "0.33.2",
"@opentelemetry/instrumentation-connect": "0.32.2",
"@opentelemetry/instrumentation-dataloader": "0.5.2",
"@opentelemetry/instrumentation-dns": "0.32.3",
"@opentelemetry/instrumentation-express": "0.33.2",
"@opentelemetry/instrumentation-fastify": "0.32.3",
"@opentelemetry/instrumentation-generic-pool": "0.32.3",
"@opentelemetry/instrumentation-graphql": "0.35.2",
"@opentelemetry/instrumentation-grpc": "0.44.0",
"@opentelemetry/instrumentation-hapi": "0.33.1",
"@opentelemetry/instrumentation-http": "0.44.0",
"@opentelemetry/instrumentation-ioredis": "0.35.2",
"@opentelemetry/instrumentation-knex": "0.32.2",
"@opentelemetry/instrumentation-koa": "0.36.1",
"@opentelemetry/instrumentation-memcached": "0.32.2",
"@opentelemetry/instrumentation-mongodb": "0.37.1",
"@opentelemetry/instrumentation-mongoose": "0.33.2",
"@opentelemetry/instrumentation-mysql": "0.34.2",
"@opentelemetry/instrumentation-mysql2": "0.34.2",
"@opentelemetry/instrumentation-nestjs-core": "0.33.2",
"@opentelemetry/instrumentation-net": "0.32.2",
"@opentelemetry/instrumentation-pg": "0.36.2",
"@opentelemetry/instrumentation-pino": "0.34.2",
"@opentelemetry/instrumentation-redis": "0.35.2",
"@opentelemetry/instrumentation-redis-4": "0.35.3",
"@opentelemetry/instrumentation-restify": "0.34.1",
"@opentelemetry/instrumentation-router": "0.33.2",
"@opentelemetry/instrumentation-tedious": "0.6.2",
"@opentelemetry/instrumentation-winston": "0.32.2",
"@opentelemetry/propagator-b3": "1.17.1",
"@opentelemetry/resources": "1.17.1",
"@opentelemetry/sdk-metrics": "1.17.1",
"@opentelemetry/sdk-trace-base": "1.17.1",
"@opentelemetry/sdk-trace-node": "1.17.1",
"@opentelemetry/semantic-conventions": "1.17.1",
"@opentelemetry/context-async-hooks": "1.18.1",
"@opentelemetry/core": "1.18.1",
"@opentelemetry/exporter-metrics-otlp-grpc": "0.45.1",
"@opentelemetry/exporter-metrics-otlp-proto": "0.45.1",
"@opentelemetry/exporter-trace-otlp-grpc": "0.45.1",
"@opentelemetry/exporter-trace-otlp-proto": "0.45.1",
"@opentelemetry/instrumentation": "0.45.1",
"@opentelemetry/instrumentation-amqplib": "0.33.4",
"@opentelemetry/instrumentation-aws-sdk": "0.37.1",
"@opentelemetry/instrumentation-bunyan": "0.34.0",
"@opentelemetry/instrumentation-cassandra-driver": "0.34.1",
"@opentelemetry/instrumentation-connect": "0.32.3",
"@opentelemetry/instrumentation-dataloader": "0.5.3",
"@opentelemetry/instrumentation-dns": "0.32.4",
"@opentelemetry/instrumentation-express": "0.34.0",
"@opentelemetry/instrumentation-fastify": "0.32.5",
"@opentelemetry/instrumentation-generic-pool": "0.32.4",
"@opentelemetry/instrumentation-graphql": "0.36.0",
"@opentelemetry/instrumentation-grpc": "0.45.1",
"@opentelemetry/instrumentation-hapi": "0.33.2",
"@opentelemetry/instrumentation-http": "0.45.1",
"@opentelemetry/instrumentation-ioredis": "0.36.0",
"@opentelemetry/instrumentation-knex": "0.32.3",
"@opentelemetry/instrumentation-koa": "0.36.3",
"@opentelemetry/instrumentation-memcached": "0.32.4",
"@opentelemetry/instrumentation-mongodb": "0.38.0",
"@opentelemetry/instrumentation-mongoose": "0.33.4",
"@opentelemetry/instrumentation-mysql": "0.34.4",
"@opentelemetry/instrumentation-mysql2": "0.34.4",
"@opentelemetry/instrumentation-nestjs-core": "0.33.3",
"@opentelemetry/instrumentation-net": "0.32.4",
"@opentelemetry/instrumentation-pg": "0.37.1",
"@opentelemetry/instrumentation-pino": "0.34.4",
"@opentelemetry/instrumentation-redis": "0.35.4",
"@opentelemetry/instrumentation-redis-4": "0.35.5",
"@opentelemetry/instrumentation-restify": "0.34.2",
"@opentelemetry/instrumentation-router": "0.33.3",
"@opentelemetry/instrumentation-tedious": "0.6.4",
"@opentelemetry/instrumentation-winston": "0.33.0",
"@opentelemetry/propagator-b3": "1.18.1",
"@opentelemetry/resources": "1.18.1",
"@opentelemetry/sdk-metrics": "1.18.1",
"@opentelemetry/sdk-trace-base": "1.18.1",
"@opentelemetry/sdk-trace-node": "1.18.1",
"@opentelemetry/semantic-conventions": "1.18.1",
"is-promise": "^4.0.0",
"nan": "^2.18.0",
"node-gyp-build": "^4.6.1",
"node-gyp-build": "^4.7.1",
"protobufjs": "^7.2.4",
"semver": "^7.5.4"
},
Expand Down
11 changes: 11 additions & 0 deletions src/instrumentations/logging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

import { Span } from '@opentelemetry/sdk-trace-base';
import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';
import type { BunyanInstrumentation } from '@opentelemetry/instrumentation-bunyan';
import { getEnvBoolean } from '../utils';

// eslint-disable-next-line @typescript-eslint/no-explicit-any
type LogRecord = Record<string, any>;
Expand Down Expand Up @@ -59,3 +61,12 @@ export function configureLogInjection(
return instrumentation.setConfig(config);
}
}

export function disableLogSending(instrumentation: BunyanInstrumentation) {
const enabled = getEnvBoolean('SPLUNK_AUTOMATIC_LOG_COLLECTION', false);
instrumentation.setConfig(
Object.assign({}, instrumentation.getConfig(), {
disableLogSending: !enabled,
})
);
}
8 changes: 7 additions & 1 deletion src/tracing/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@
} from '@opentelemetry/context-async-hooks';

import { configureHttpInstrumentation } from '../instrumentations/http';
import { configureLogInjection } from '../instrumentations/logging';
import {
configureLogInjection,
disableLogSending,
} from '../instrumentations/logging';
import { allowedTracingOptions, Options, _setDefaultOptions } from './options';
import { configureRedisInstrumentation } from '../instrumentations/redis';
import {
Expand Down Expand Up @@ -182,7 +185,7 @@
function isShutDownable(
tracerProvider: TracerProvider
): tracerProvider is ShutDownableTracerProvider {
return typeof (tracerProvider as any).shutdown === 'function';

Check warning on line 188 in src/tracing/index.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
}

async function shutdownGlobalTracerProvider() {
Expand Down Expand Up @@ -221,6 +224,9 @@
configureRedisInstrumentation(instr, options);
break;
case '@opentelemetry/instrumentation-bunyan':
disableLogSending(instr);
configureLogInjection(instr);
break;
case '@opentelemetry/instrumentation-pino':
case '@opentelemetry/instrumentation-winston':
configureLogInjection(instr);
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export type EnvVarKey =
| 'OTEL_TRACES_EXPORTER'
| 'SPLUNK_ACCESS_TOKEN'
| 'SPLUNK_AUTOINSTRUMENT_PACKAGE_NAMES'
| 'SPLUNK_AUTOMATIC_LOG_COLLECTION'
| 'SPLUNK_DEBUG_METRICS_ENABLED'
| 'SPLUNK_INSTRUMENTATION_METRICS_ENABLED'
| 'SPLUNK_METRICS_ENABLED'
Expand Down
55 changes: 55 additions & 0 deletions test/loginjection.bunyan.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright Splunk Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { TestLogStream, assertInjection } from './utils';
import { startTracing, stopTracing } from '../src/tracing';
import type * as bunyan from 'bunyan';

describe('log injection', () => {
let logStream: TestLogStream;

beforeEach(() => {
logStream = new TestLogStream();
});

describe('injecting version and environment', () => {
before(() => {
process.env.OTEL_RESOURCE_ATTRIBUTES =
'service.version=1,deployment.environment=test';
});

after(() => {
delete process.env.OTEL_RESOURCE_ATTRIBUTES;
});

it('injects service version and service environment if available', () => {
startTracing({ serviceName: 'test-service' });

const logger: bunyan = require('bunyan').createLogger({
name: 'test',
stream: logStream.stream,
});

assertInjection(logStream, logger, [
['service.name', 'test-service'],
['service.version', '1'],
['service.environment', 'test'],
]);

stopTracing();
});
});
});
77 changes: 77 additions & 0 deletions test/loginjection.pino.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* Copyright Splunk Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import type * as pino from 'pino';
import { startTracing, stopTracing } from '../src/tracing';
import { TestLogStream, assertInjection } from './utils';
import { defaultLogHook } from '../src/instrumentations/logging';
import { PinoInstrumentation } from '@opentelemetry/instrumentation-pino';

describe('pino with with custom hooks', () => {
let logStream: TestLogStream;

beforeEach(() => {
logStream = new TestLogStream();
});
afterEach(() => {
stopTracing();
});

it('is possible to opt out from injecting resource attributes', () => {
const MY_VALUE = 'myValue';
const MY_ATTRIBUTE = 'myAttribute';
startTracing({
serviceName: 'test-service',
instrumentations: [
new PinoInstrumentation({
logHook: (span, logRecord) => {
logRecord[MY_ATTRIBUTE] = MY_VALUE;
},
}),
],
});

const logger: pino.Logger = require('pino')(logStream.stream);

assertInjection(logStream, logger, [
['service.name', undefined],
[MY_ATTRIBUTE, MY_VALUE],
]);
});

it('is easy enough do do both', () => {
const MY_VALUE = 'myValueBoth';
const MY_ATTRIBUTE = 'myAttributeBoth';
startTracing({
serviceName: 'test-service',
instrumentations: [
new PinoInstrumentation({
logHook: (span, logRecord) => {
defaultLogHook(span, logRecord);
logRecord[MY_ATTRIBUTE] = MY_VALUE;
},
}),
],
});

const logger: pino.Logger = require('pino')(logStream.stream);

assertInjection(logStream, logger, [
['service.name', 'test-service'],
[MY_ATTRIBUTE, MY_VALUE],
]);
});
});
Loading
Loading