Skip to content

Commit

Permalink
Merge branch 'main' into fix/build-types-2
Browse files Browse the repository at this point in the history
  • Loading branch information
rauno56 authored Sep 12, 2022
2 parents a8e2ac2 + 954f29c commit cba5b69
Show file tree
Hide file tree
Showing 26 changed files with 134 additions and 263 deletions.
1 change: 1 addition & 0 deletions .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ jobs:
- node: "12"
lerna-extra-args: >-
--ignore @opentelemetry/instrumentation-redis-4
--ignore @opentelemetry/instrumentation-pino
runs-on: ubuntu-latest
services:
memcached:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,4 @@ package.json.lerna_backup

# version.ts file is automatically generated at compile time
version.ts
/.vs
2 changes: 1 addition & 1 deletion karma.base.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module.exports = {
listenAddress: 'localhost',
hostname: 'localhost',
browsers: ['ChromeHeadless'],
frameworks: ['mocha', 'webpack'],
frameworks: ['mocha'],
coverageIstanbulReporter: {
reports: ['json'],
dir: '.nyc_output',
Expand Down
2 changes: 1 addition & 1 deletion karma.webpack.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const webpackNodePolyfills = require('./webpack.node-polyfills.js');
module.exports = {
mode: 'development',
target: 'web',
name: 'bundle',
output: { filename: 'bundle.js' },
resolve: { extensions: ['.ts', '.js', '.tsx'] },
devtool: 'inline-source-map',
module: {
Expand Down
21 changes: 1 addition & 20 deletions metapackages/auto-instrumentations-web/karma.conf.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* Copyright The OpenTelemetry Authors
* Copyright 2020, OpenTelemetry Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -14,29 +14,10 @@
* limitations under the License.
*/

const webpack = require('webpack');

const karmaWebpackConfig = require('../../karma.webpack');
const karmaBaseConfig = require('../../karma.base');

module.exports = (config) => {
{
const plugins = karmaWebpackConfig.plugins = [];
plugins.push(new webpack.ProvidePlugin({
process: 'process/browser',
}));
}

{
const plugins = karmaBaseConfig.plugins = [];
const toAdd = Object.keys(require('./package.json').devDependencies)
.filter((packageName) => packageName.startsWith('karma-'))
.map((packageName) => require(packageName));
plugins.push(
...toAdd
);
}

config.set(Object.assign({}, karmaBaseConfig, {
webpack: karmaWebpackConfig
}))
Expand Down
17 changes: 7 additions & 10 deletions metapackages/auto-instrumentations-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,32 +34,29 @@
},
"devDependencies": {
"@babel/core": "7.15.0",
"@jsdevtools/coverage-istanbul-loader": "3.0.5",
"@opentelemetry/api": "^1.0.0",
"@types/mocha": "8.2.3",
"@types/node": "16.11.21",
"@types/sinon": "10.0.2",
"@types/webpack-env": "1.16.2",
"assert": "2.0.0",
"babel-loader": "8.2.2",
"gts": "3.1.0",
"karma": "6.3.17",
"karma-chrome-launcher": "3.1.1",
"@jsdevtools/coverage-istanbul-loader": "3.0.5",
"karma": "6.3.16",
"karma-chrome-launcher": "3.1.0",
"karma-coverage-istanbul-reporter": "3.0.3",
"karma-mocha": "2.0.1",
"karma-spec-reporter": "0.0.33",
"karma-webpack": "5.0.0",
"karma-spec-reporter": "0.0.32",
"karma-webpack": "4.0.2",
"mocha": "7.2.0",
"nyc": "15.1.0",
"process": "0.11.10",
"rimraf": "3.0.2",
"sinon": "14.0.0",
"ts-loader": "8.3.0",
"ts-mocha": "10.0.0",
"typescript": "4.3.5",
"util": "0.12.4",
"webpack": "5.72.0",
"webpack-cli": "4.9.2",
"webpack": "4.46.0",
"webpack-cli": "4.7.2",
"webpack-merge": "5.8.0"
},
"dependencies": {
Expand Down
29 changes: 6 additions & 23 deletions packages/opentelemetry-id-generator-aws-xray/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,13 @@
* limitations under the License.
*/

const webpack = require('webpack');

const karmaWebpackConfig = require('../../karma.webpack');
const karmaBaseConfig = require('../../karma.base');

module.exports = (config) => {
{
const plugins = karmaWebpackConfig.plugins = [];
plugins.push(new webpack.ProvidePlugin({
process: 'process/browser',
}));
}

{
const plugins = karmaBaseConfig.plugins = [];
const toAdd = Object.keys(require('./package.json').devDependencies)
.filter((packageName) => packageName.startsWith('karma-'))
.map((packageName) => require(packageName));
plugins.push(
...toAdd
);
}

config.set(Object.assign({}, karmaBaseConfig, {
webpack: karmaWebpackConfig
}))
module.exports = config => {
config.set(
Object.assign({}, karmaBaseConfig, {
webpack: karmaWebpackConfig,
})
);
};
14 changes: 6 additions & 8 deletions packages/opentelemetry-id-generator-aws-xray/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,29 +54,27 @@
"@opentelemetry/api": "^1.0.0"
},
"devDependencies": {
"@jsdevtools/coverage-istanbul-loader": "3.0.5",
"@opentelemetry/api": "^1.0.0",
"@types/mocha": "8.2.3",
"@types/node": "16.11.21",
"@types/sinon": "10.0.2",
"@types/webpack-env": "1.16.2",
"assert": "2.0.0",
"gts": "3.1.0",
"karma": "6.3.17",
"karma-chrome-launcher": "3.1.1",
"@jsdevtools/coverage-istanbul-loader": "3.0.5",
"karma": "6.3.16",
"karma-chrome-launcher": "3.1.0",
"karma-coverage-istanbul-reporter": "3.0.3",
"karma-mocha": "2.0.1",
"karma-spec-reporter": "0.0.33",
"karma-webpack": "5.0.0",
"karma-spec-reporter": "0.0.32",
"karma-webpack": "4.0.2",
"mocha": "7.2.0",
"nyc": "15.1.0",
"process": "0.11.10",
"rimraf": "3.0.2",
"sinon": "14.0.0",
"ts-loader": "8.3.0",
"ts-mocha": "10.0.0",
"typescript": "4.3.5",
"webpack": "5.72.0"
"webpack": "4.46.0"
},
"dependencies": {
"@opentelemetry/core": "^1.0.0"
Expand Down
15 changes: 11 additions & 4 deletions plugins/node/opentelemetry-instrumentation-pino/.tav.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
pino:
versions: "^7.11.0 || 7.8.0 || 7.2.0 || ^6.13.1 || 5.17.0 || 5.14.0"
commands: npm run test
- versions: "^8.0.0 || ^7.11.0 || 7.8.0 || 7.2.0 || ^6.13.1 || 5.17.0 || 5.14.0"
node: ">=14"
commands: npm run test

# Fix missing `contrib-test-utils` package
pretest: npm run --prefix ../../../ lerna:link
# Fix missing `contrib-test-utils` package
pretest: npm run --prefix ../../../ lerna:link
- versions: "^7.11.0 || 7.8.0 || 7.2.0 || ^6.13.1 || 5.17.0 || 5.14.0"
node: ">=8 <14"
commands: npm run test

# Fix missing `contrib-test-utils` package
pretest: npm run --prefix ../../../ lerna:link
2 changes: 1 addition & 1 deletion plugins/node/opentelemetry-instrumentation-pino/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ When no span context is active or the span context is invalid, injection is skip

### Supported versions

`>=5.14.0 <8`
`>=5.14.0 <9`

## Useful links

Expand Down
6 changes: 3 additions & 3 deletions plugins/node/opentelemetry-instrumentation-pino/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,16 @@
"gts": "3.1.0",
"mocha": "7.2.0",
"nyc": "15.1.0",
"pino": "8.3.1",
"rimraf": "3.0.2",
"semver": "7.3.5",
"sinon": "14.0.0",
"test-all-versions": "5.0.1",
"ts-mocha": "10.0.0",
"typescript": "4.3.5"
},
"dependencies": {
"@opentelemetry/instrumentation": "^0.32.0",
"pino": "7.10.0",
"semver": "^7.3.5"
"@opentelemetry/instrumentation": "^0.32.0"
},
"homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-pino#readme"
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,10 @@ import {
InstrumentationNodeModuleDefinition,
safeExecuteInTheMiddle,
} from '@opentelemetry/instrumentation';
import { Pino, PinoInstrumentationConfig } from './types';
import { PinoInstrumentationConfig } from './types';
import { VERSION } from './version';
import type { pino } from 'pino';

const pinoVersions = ['>=5.14.0 <8'];
const pinoVersions = ['>=5.14.0 <9'];

export class PinoInstrumentation extends InstrumentationBase {
constructor(config: PinoInstrumentationConfig = {}) {
Expand All @@ -39,7 +38,7 @@ export class PinoInstrumentation extends InstrumentationBase {

protected init() {
return [
new InstrumentationNodeModuleDefinition<Pino>(
new InstrumentationNodeModuleDefinition<any>(
'pino',
pinoVersions,
pinoModule => {
Expand All @@ -61,17 +60,22 @@ export class PinoInstrumentation extends InstrumentationBase {
args.splice(0, 0, {
mixin: instrumentation._getMixinFunction(),
});
return pinoModule(...(args as Parameters<Pino>));
return pinoModule(...args);
}
}

args[0] = instrumentation._combineOptions(
args[0] as pino.LoggerOptions
);
args[0] = instrumentation._combineOptions(args[0]);

return pinoModule(...(args as Parameters<Pino>));
return pinoModule(...args);
}, pinoModule);

if (typeof patchedPino.pino === 'function') {
patchedPino.pino = patchedPino;
}
if (typeof patchedPino.default === 'function') {
patchedPino.default = patchedPino;
}

return patchedPino;
}
),
Expand Down Expand Up @@ -135,7 +139,7 @@ export class PinoInstrumentation extends InstrumentationBase {
};
}

private _combineOptions(options?: pino.LoggerOptions) {
private _combineOptions(options?: any) {
if (options === undefined) {
return { mixin: this._getMixinFunction() };
}
Expand Down
3 changes: 0 additions & 3 deletions plugins/node/opentelemetry-instrumentation-pino/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

import { Span } from '@opentelemetry/api';
import { InstrumentationConfig } from '@opentelemetry/instrumentation';
import type { pino } from 'pino';

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export type LogHookFunction = (
Expand All @@ -28,5 +27,3 @@ export type LogHookFunction = (
export interface PinoInstrumentationConfig extends InstrumentationConfig {
logHook?: LogHookFunction;
}

export type Pino = typeof pino;
35 changes: 32 additions & 3 deletions plugins/node/opentelemetry-instrumentation-pino/test/pino.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,16 @@ describe('PinoInstrumentation', () => {
return record;
}

function init() {
function init(importType: 'global' | 'default' | 'pino' = 'global') {
stream = new Writable();
stream._write = () => {};
writeSpy = sinon.spy(stream, 'write');
logger = pino(stream);
if (importType === 'global') {
logger = pino(stream);
} else {
// @ts-expect-error the same function reexported
logger = pino[importType](stream);
}
}

before(() => {
Expand All @@ -100,6 +105,30 @@ describe('PinoInstrumentation', () => {
});
});

it('injects span context to records in default export', function () {
// @ts-expect-error the same function reexported
if (!pino.default) {
this.skip();
}
init('default');
const span = tracer.startSpan('abc');
context.with(trace.setSpan(context.active(), span), () => {
testInjection(span);
});
});

it('injects span context to records in named export', function () {
// @ts-expect-error the same function reexported
if (!pino.pino) {
this.skip();
}
init('pino');
const span = tracer.startSpan('abc');
context.with(trace.setSpan(context.active(), span), () => {
testInjection(span);
});
});

it('injects span context to child logger records', () => {
const span = tracer.startSpan('abc');
context.with(trace.setSpan(context.active(), span), () => {
Expand Down Expand Up @@ -243,7 +272,7 @@ describe('PinoInstrumentation', () => {
instrumentation.enable();
});

beforeEach(init);
beforeEach(() => init());

it('does not inject span context', () => {
const span = tracer.startSpan('abc');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,10 @@
* limitations under the License.
*/

const webpack = require('webpack');

const karmaWebpackConfig = require('../../../karma.webpack');
const karmaBaseConfig = require('../../../karma.base');

module.exports = (config) => {
{
const plugins = karmaWebpackConfig.plugins = [];
plugins.push(new webpack.ProvidePlugin({
process: 'process/browser',
}));
}

{
const plugins = karmaBaseConfig.plugins = [];
const toAdd = Object.keys(require('./package.json').devDependencies)
.filter((packageName) => packageName.startsWith('karma-'))
.map((packageName) => require(packageName));
plugins.push(
...toAdd
);
}

config.set(Object.assign({}, karmaBaseConfig, {
webpack: karmaWebpackConfig
}))
Expand Down
Loading

0 comments on commit cba5b69

Please sign in to comment.