Skip to content

Commit

Permalink
Merge 07a3f0f into c8c4ec6
Browse files Browse the repository at this point in the history
  • Loading branch information
gregolsen authored Jun 13, 2022
2 parents c8c4ec6 + 07a3f0f commit e36c928
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 5 deletions.
1 change: 1 addition & 0 deletions experimental/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ All notable changes to experimental packages in this project will be documented

### :rocket: (Enhancement)

* feat(opentelemetry-instrumentation-fetch): optionally ignore network events #3028 @gregolsen
* feat(http-instrumentation): record exceptions in http instrumentation #3008 @luismiramirez

### :bug: (Bug Fix)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,10 @@ See [examples/tracer-web/fetch](https://github.com/open-telemetry/opentelemetry-

Fetch instrumentation plugin has few options available to choose from. You can set the following:

| Options | Type | Description |
| ------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------- | ------------------------------------- |
| [`applyCustomAttributesOnSpan`](https://github.com/open-telemetry/opentelemetry-js/blob/main/experimental/packages/opentelemetry-instrumentation-fetch/src/fetch.ts#L64) | `HttpCustomAttributeFunction` | Function for adding custom attributes |
| Options | Type | Description |
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------|-----------------------------------------------------------------------------------------|
| [`applyCustomAttributesOnSpan`](https://github.com/open-telemetry/opentelemetry-js/blob/main/experimental/packages/opentelemetry-instrumentation-fetch/src/fetch.ts#L64) | `HttpCustomAttributeFunction` | Function for adding custom attributes |
| [`ignoreNetworkEvents`](https://github.com/open-telemetry/opentelemetry-js/blob/main/experimental/packages/opentelemetry-instrumentation-fetch/src/fetch.ts#L67) | `boolean` | Disable network events being added as span events (network events are added by default) |

## Useful links

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ export interface FetchInstrumentationConfig extends InstrumentationConfig {
ignoreUrls?: Array<string | RegExp>;
/** Function for adding custom attributes on the span */
applyCustomAttributesOnSpan?: FetchCustomAttributeFunction;
// Ignore adding network events as span events
ignoreNetworkEvents?: boolean;
}

/**
Expand Down Expand Up @@ -105,7 +107,9 @@ export class FetchInstrumentation extends InstrumentationBase<Promise<Response>>
},
api.trace.setSpan(api.context.active(), span)
);
web.addSpanNetworkEvents(childSpan, corsPreFlightRequest);
if (!this._getConfig().ignoreNetworkEvents) {
web.addSpanNetworkEvents(childSpan, corsPreFlightRequest);
}
childSpan.end(
corsPreFlightRequest[web.PerformanceTimingNames.RESPONSE_END]
);
Expand Down Expand Up @@ -247,7 +251,9 @@ export class FetchInstrumentation extends InstrumentationBase<Promise<Response>>
this._addChildSpan(span, corsPreFlightRequest);
this._markResourceAsUsed(corsPreFlightRequest);
}
web.addSpanNetworkEvents(span, mainRequest);
if (!this._getConfig().ignoreNetworkEvents) {
web.addSpanNetworkEvents(span, mainRequest);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -900,4 +900,20 @@ describe('fetch', () => {
);
});
});

describe('when network events are ignored', () => {
beforeEach(async () => {
await prepareData(url, {
ignoreNetworkEvents: true,
});
});
afterEach(() => {
clearData();
});
it('should NOT add network events', () => {
const span: tracing.ReadableSpan = exportSpy.args[1][0][0];
const events = span.events;
assert.strictEqual(events.length, 0, 'number of events is wrong');
});
});
});

0 comments on commit e36c928

Please sign in to comment.