Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
29 changes: 26 additions & 3 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ module.exports = {
"node",
"prettier"
],
extends: ["eslint:recommended", "plugin:@typescript-eslint/recommended", "plugin:prettier/recommended"],
extends: ["eslint:recommended", "plugin:prettier/recommended"],
parser: "@typescript-eslint/parser",
parserOptions: {
"project": "./tsconfig.json"
"project": null
},
rules: {
"quotes": ["error", "single", { "avoidEscape": true }],
Expand All @@ -28,6 +28,11 @@ module.exports = {
overrides: [
{
files: ['*.ts'],
// Enable typescript-eslint for ts files.
extends: ["eslint:recommended", "plugin:@typescript-eslint/recommended", "plugin:prettier/recommended"],
parserOptions: {
"project": "./tsconfig.json"
},
rules: {
"@typescript-eslint/no-floating-promises": "error",
"@typescript-eslint/no-this-alias": "off",
Expand All @@ -49,21 +54,39 @@ module.exports = {
}
}],
"@typescript-eslint/no-shadow": ["warn"],
"prefer-rest-params": "off",
}
},
{
files: ["test/**/*.ts"],
// Enable typescript-eslint for ts files.
extends: ["eslint:recommended", "plugin:@typescript-eslint/recommended", "plugin:prettier/recommended"],
parserOptions: {
"project": "./tsconfig.json"
},
rules: {
"no-empty": "off",
"@typescript-eslint/ban-ts-ignore": "off",
"@typescript-eslint/ban-types": ["warn", {
"types": {
"Function": null,
}
}],
"@typescript-eslint/no-empty-function": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-unused-vars": "off",
"@typescript-eslint/no-var-requires": "off",
"@typescript-eslint/no-shadow": ["off"],
"@typescript-eslint/no-floating-promises": ["off"],
"@typescript-eslint/no-non-null-assertion": ["off"],
"@typescript-eslint/explicit-module-boundary-types": ["off"]
"@typescript-eslint/explicit-module-boundary-types": ["off"],
"prefer-rest-params": "off",
}
},
{
files: ["*.mjs"],
parserOptions: {
sourceType: 'module',
}
}
]
Expand Down
26 changes: 26 additions & 0 deletions examples/bunyan/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright The OpenTelemetry Authors
*
* 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
*
* https://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.
*/

'use strict';

const baseConfig = require('../../eslint.config');

module.exports = {
...baseConfig,
env: {
node: true,
},
};
6 changes: 4 additions & 2 deletions examples/bunyan/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,18 @@
* limitations under the License.
*/

'use strict';

// A small example that shows using OpenTelemetry's instrumentation of
// Bunyan loggers. Usage:
// node --require ./telemetry.js app.js

const otel = require('@opentelemetry/api');
const bunyan = require('bunyan');

const log = bunyan.createLogger({name: 'myapp', level: 'debug'});
const log = bunyan.createLogger({ name: 'myapp', level: 'debug' });

log.debug({foo: 'bar'}, 'hi');
log.debug({ foo: 'bar' }, 'hi');

const tracer = otel.trace.getTracer('example');
tracer.startActiveSpan('manual-span', span => {
Expand Down
5 changes: 2 additions & 3 deletions examples/bunyan/app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,12 @@
import { trace } from '@opentelemetry/api';
import bunyan from 'bunyan';

const log = bunyan.createLogger({name: 'myapp', level: 'debug'});
const log = bunyan.createLogger({ name: 'myapp', level: 'debug' });

log.debug({foo: 'bar'}, 'hi');
log.debug({ foo: 'bar' }, 'hi');

const tracer = trace.getTracer('example');
tracer.startActiveSpan('manual-span', span => {
log.info('this record will have trace_id et al fields for the current span');
span.end();
});

2 changes: 2 additions & 0 deletions examples/bunyan/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
"version": "0.1.0",
"description": "Example of Bunyan integration with OpenTelemetry",
"scripts": {
"lint": "eslint . --ext=ts,js,mjs",
"lint:fix": "eslint . --ext=ts,js,mjs --fix",
"start": "node -r ./telemetry.js app.js"
},
"repository": {
Expand Down
34 changes: 22 additions & 12 deletions examples/bunyan/telemetry.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,25 @@
* limitations under the License.
*/

'use strict';

// Setup telemetry for tracing and Bunyan logging.
//
// This writes OTel spans and log records to the console for simplicity. In a
// real setup you would configure exporters to send to remote observability apps
// for viewing and analysis.

const { NodeSDK, tracing, logs, api } = require('@opentelemetry/sdk-node');
const { envDetectorSync, hostDetectorSync, processDetectorSync } = require('@opentelemetry/resources');
const { NodeSDK, tracing, logs } = require('@opentelemetry/sdk-node');
const {
envDetectorSync,
hostDetectorSync,
processDetectorSync,
} = require('@opentelemetry/resources');
// api.diag.setLogger(new api.DiagConsoleLogger(), api.DiagLogLevel.DEBUG);

const { BunyanInstrumentation } = require('@opentelemetry/instrumentation-bunyan');
const {
BunyanInstrumentation,
} = require('@opentelemetry/instrumentation-bunyan');

const sdk = new NodeSDK({
serviceName: 'bunyan-example',
Expand All @@ -36,20 +44,22 @@ const sdk = new NodeSDK({
// The HostDetector adds `host.name` and `host.arch` fields. `host.name`
// replaces the usual Bunyan `hostname` field. HostDetector is *not* a
// default detector of the `NodeSDK`.
hostDetectorSync
hostDetectorSync,
],
spanProcessor: new tracing.SimpleSpanProcessor(new tracing.ConsoleSpanExporter()),
logRecordProcessor: new logs.SimpleLogRecordProcessor(new logs.ConsoleLogRecordExporter()),
instrumentations: [
new BunyanInstrumentation(),
]
})
process.on("SIGTERM", () => {
spanProcessor: new tracing.SimpleSpanProcessor(
new tracing.ConsoleSpanExporter()
),
logRecordProcessor: new logs.SimpleLogRecordProcessor(
new logs.ConsoleLogRecordExporter()
),
instrumentations: [new BunyanInstrumentation()],
});
process.on('SIGTERM', () => {
sdk
.shutdown()
.then(
() => {},
(err) => console.log("warning: error shutting down OTel SDK", err)
err => console.log('warning: error shutting down OTel SDK', err)
)
.finally(() => process.exit(0));
});
Expand Down