Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
59f11f3
feat(instrumentation-bunyan): add log sending to Logs Bridge API
trentm Sep 22, 2023
7d8a21f
Merge branch 'main' into trentm/logs-bridge-bunyan
trentm Oct 3, 2023
03c1c16
markdown lint fixes
trentm Oct 3, 2023
3fbfc0c
markdown lint fixes
trentm Oct 3, 2023
57b6628
Merge branch 'main' into trentm/logs-bridge-bunyan
trentm Oct 15, 2023
d5a92d1
catch up with recent core-deps update
trentm Oct 15, 2023
5b9aecb
some type tweaks suggested by David
trentm Oct 15, 2023
e3ed22c
more specific type
trentm Nov 8, 2023
bd507e2
use more self-explanatory code for mapping Bunyan level to OTel sever…
trentm Nov 8, 2023
45f2b1d
export OpenTelemetryBunyanStream for direct usage in Bunyan loggers w…
trentm Nov 8, 2023
7d1532f
.apply over .call suggestion
trentm Nov 8, 2023
ed9ddaf
consistency suggestion
trentm Nov 8, 2023
0f77516
suggestion to use the longer (perhaps clearer) logger var name
trentm Nov 8, 2023
aa81256
Merge branch 'main' into trentm/logs-bridge-bunyan
trentm Nov 8, 2023
4c94dba
switch to false-by-default config vars to avoid surprises with undefi…
trentm Nov 8, 2023
21e3a55
document using OpenTelemetryBunyanStream without the instrumentation
trentm Nov 8, 2023
44d20bd
fix https://eslint.org/docs/latest/rules/prefer-spread lint error
trentm Nov 9, 2023
751f95a
drop options to OpenTelemetryBunyanStream constructor because YAGNI
trentm Nov 9, 2023
43ab672
Merge branch 'main' into trentm/logs-bridge-bunyan
trentm Nov 9, 2023
2f0a89a
temporarily drop CI caching to test theory on unit-test (18) CI failure
trentm Nov 9, 2023
c283178
more CI debugging: restore cache, add some 'npm ls -a' to look into N…
trentm Nov 9, 2023
3638f72
elide Bunyan 'pid' and 'hostname' fields in OTel log record attributes
trentm Nov 9, 2023
303b6ab
update test for having elided 'pid' and 'hostname' fields
trentm Nov 9, 2023
018118e
CI debugging: ignore the 'npm ls -a' exit status, they shouldn't brea…
trentm Nov 9, 2023
284e4d6
fix lint and compile errors
trentm Nov 9, 2023
7fc0842
CI debugging: turn on diag DEBUG to test a theory
trentm Nov 10, 2023
54d2477
turn off diag in this example
trentm Nov 11, 2023
6de5de1
undo CI debugging changes
trentm Nov 11, 2023
bb9b2e4
Merge branch 'main' into trentm/logs-bridge-bunyan
trentm Nov 11, 2023
af2a216
Merge branch 'main' into trentm/logs-bridge-bunyan
hectorhdzg Nov 20, 2023
f3c4d03
update deps to current releases and sync package-lock.json
trentm Nov 21, 2023
c740b76
disableInjection -> disableLogCorrelation
trentm Nov 22, 2023
f850a63
disableLogsBridge -> disableLogSending
trentm Nov 23, 2023
45cbb8b
Merge branch 'main' into trentm/logs-bridge-bunyan
trentm Nov 23, 2023
b597a92
Merge branch 'main' into trentm/logs-bridge-bunyan
hectorhdzg Nov 27, 2023
39b8507
correct the default instrumentation scope name (as discussed earlier)
trentm Nov 27, 2023
a149912
tests: fix test for intrumentationScope.name change in previous commit
trentm Nov 27, 2023
ca18034
fix lint
trentm Nov 27, 2023
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
Prev Previous commit
Next Next commit
switch to false-by-default config vars to avoid surprises with undefi…
  • Loading branch information
trentm committed Nov 8, 2023
commit 4c94dbac52856cdf40f8659f9b2ab70dfa71533d
16 changes: 8 additions & 8 deletions plugins/node/opentelemetry-instrumentation-bunyan/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ npm install --save @opentelemetry/instrumentation-bunyan

## Supported Versions

- `^1.0.0`
- `bunyan@^1.0.0`

## Usage

Expand Down Expand Up @@ -54,7 +54,7 @@ Creation of a Bunyan Logger will automatically add a [Bunyan stream](https://git

If the OpenTelemetry SDK is not configured with a Logger provider, then this added stream will be a no-op.

The logs bridge can be disabled with the `enableLogsBridge: false` option.
The logs bridge can be disabled with the `disableLogsBridge: true` option.

### Log injection

Expand All @@ -74,15 +74,15 @@ After adding these fields, the optional `logHook` is called to allow injecting a
```

When no span context is active or the span context is invalid, injection is skipped.
Log injection can be disabled with the `enableInjection: false` option.
Log injection can be disabled with the `disableInjection: true` option.

### Bunyan instrumentation options

| Option | Type | Description |
| ------------------ | ----------------- | ----------- |
| `enableLogsBridge` | `boolean` | Whether [logs bridging](#logs-bridge) is enabled. Default `true`. |
| `enableInjection` | `boolean` | Whether [log injection](#log-injection) is enabled. Default `true`. |
| `logHook` | `LogHookFunction` | An option hook to inject additional context to a log record after span context has been added. This requires `enableInjection` to be true. |
| Option | Type | Description |
| ------------------- | ----------------- | ----------- |
| `disableLogsBridge` | `boolean` | Whether to disable [logs bridging](#logs-bridge). Default `false`. |
| `disableInjection` | `boolean` | Whether to disable [log injection](#log-injection). Default `false`. |
| `logHook` | `LogHookFunction` | An option hook to inject additional context to a log record after span context has been added. This requires `disableInjection` to be false. |

## Useful links

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ import { OpenTelemetryBunyanStream } from './OpenTelemetryBunyanStream';
import type * as BunyanLogger from 'bunyan';

const DEFAULT_CONFIG: BunyanInstrumentationConfig = {
enableLogsBridge: true,
enableInjection: true,
disableLogsBridge: false,
disableInjection: false,
};

export class BunyanInstrumentation extends InstrumentationBase<
Expand Down Expand Up @@ -114,7 +114,7 @@ export class BunyanInstrumentation extends InstrumentationBase<
const instrumentation = this;
return function patchedEmit(this: BunyanLogger, ...args: unknown[]) {
const config = instrumentation.getConfig();
if (!instrumentation.isEnabled() || !config.enableInjection) {
if (!instrumentation.isEnabled() || config.disableInjection) {
return original.apply(this, args);
}

Expand Down Expand Up @@ -153,7 +153,7 @@ export class BunyanInstrumentation extends InstrumentationBase<

private _addStream(logger: any) {
const config: BunyanInstrumentationConfig = this.getConfig();
if (!this.isEnabled() || !config.enableLogsBridge) {
if (!this.isEnabled() || config.disableLogsBridge) {
return;
}
this._diag.debug('Adding OpenTelemetryBunyanStream to logger');
Expand Down
16 changes: 8 additions & 8 deletions plugins/node/opentelemetry-instrumentation-bunyan/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,23 @@ export type LogHookFunction = (span: Span, record: Record<string, any>) => void;

export interface BunyanInstrumentationConfig extends InstrumentationConfig {
/**
* Whether to enable the automatic sending of log records to the OpenTelemetry
* Logs Bridge API.
* @default true
* Whether to disable the automatic sending of log records to the
* OpenTelemetry Logs Bridge API.
* @default false
*/
enableLogsBridge?: boolean;
disableLogsBridge?: boolean;

/**
* Whether to enable the injection of data such as trace-context fields into
* Whether to disable the injection of data such as trace-context fields into
* log output.
* @default true
* @default false
*/
enableInjection?: boolean;
disableInjection?: boolean;

/**
* A function that allows injecting additional fields in log records. It is
* called, as `logHook(span, record)`, for each log record emitted in a valid
* span context. It requires `enableInjection` to be true.
* span context. It requires `disableInjection` to be false.
*/
logHook?: LogHookFunction;
}
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,9 @@ describe('BunyanInstrumentation', () => {
});
});

it('does not inject or call logHook if enableInjection=false', () => {
it('does not inject or call logHook if disableInjection=true', () => {
instrumentation.setConfig({
enableInjection: false,
disableInjection: true,
logHook: (_span, record) => {
record['resource.service.name'] = 'test-service';
},
Expand Down Expand Up @@ -268,10 +268,10 @@ describe('BunyanInstrumentation', () => {
assert.strictEqual(rec.severityText, undefined);
});

it('does not emit to the Logs Bridge API if enableLogsBridge=false', () => {
instrumentation.setConfig({ enableLogsBridge: false });
it('does not emit to the Logs Bridge API if disableLogsBridge=true', () => {
instrumentation.setConfig({ disableLogsBridge: true });

// Changing `enableLogsBridge` only has an impact on Loggers created
// Changing `disableLogsBridge` only has an impact on Loggers created
// *after* it is set. So we cannot test with the `log` created in
// `beforeEach()` above.
log = Logger.createLogger({ name: 'test-logger-name', stream });
Expand Down