File tree Expand file tree Collapse file tree 4 files changed +29
-5
lines changed
packages/opentelemetry-instrumentation-fetch Expand file tree Collapse file tree 4 files changed +29
-5
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ All notable changes to experimental packages in this project will be documented
1010
1111### :rocket : (Enhancement)
1212
13+ * feat(opentelemetry-instrumentation-fetch): optionally ignore network events #3028 @gregolsen
1314* feat(http-instrumentation): record exceptions in http instrumentation #3008 @luismiramirez
1415
1516### :bug : (Bug Fix)
Original file line number Diff line number Diff line change @@ -62,9 +62,10 @@ See [examples/tracer-web/fetch](https://github.com/open-telemetry/opentelemetry-
6262
6363Fetch instrumentation plugin has few options available to choose from. You can set the following:
6464
65- | Options | Type | Description |
66- | ------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------- | ------------------------------------- |
67- | [ ` 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 |
65+ | Options | Type | Description |
66+ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -------------------------------| -----------------------------------------------------------------------------------------|
67+ | [ ` 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 |
68+ | [ ` 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) |
6869
6970## Useful links
7071
Original file line number Diff line number Diff line change @@ -63,6 +63,8 @@ export interface FetchInstrumentationConfig extends InstrumentationConfig {
6363 ignoreUrls ?: Array < string | RegExp > ;
6464 /** Function for adding custom attributes on the span */
6565 applyCustomAttributesOnSpan ?: FetchCustomAttributeFunction ;
66+ // Ignore adding network events as span events
67+ ignoreNetworkEvents ?: boolean ;
6668}
6769
6870/**
@@ -105,7 +107,9 @@ export class FetchInstrumentation extends InstrumentationBase<Promise<Response>>
105107 } ,
106108 api . trace . setSpan ( api . context . active ( ) , span )
107109 ) ;
108- web . addSpanNetworkEvents ( childSpan , corsPreFlightRequest ) ;
110+ if ( ! this . _getConfig ( ) . ignoreNetworkEvents ) {
111+ web . addSpanNetworkEvents ( childSpan , corsPreFlightRequest ) ;
112+ }
109113 childSpan . end (
110114 corsPreFlightRequest [ web . PerformanceTimingNames . RESPONSE_END ]
111115 ) ;
@@ -247,7 +251,9 @@ export class FetchInstrumentation extends InstrumentationBase<Promise<Response>>
247251 this . _addChildSpan ( span , corsPreFlightRequest ) ;
248252 this . _markResourceAsUsed ( corsPreFlightRequest ) ;
249253 }
250- web . addSpanNetworkEvents ( span , mainRequest ) ;
254+ if ( ! this . _getConfig ( ) . ignoreNetworkEvents ) {
255+ web . addSpanNetworkEvents ( span , mainRequest ) ;
256+ }
251257 }
252258 }
253259
Original file line number Diff line number Diff line change @@ -900,4 +900,20 @@ describe('fetch', () => {
900900 ) ;
901901 } ) ;
902902 } ) ;
903+
904+ describe ( 'when network events are ignored' , ( ) => {
905+ beforeEach ( async ( ) => {
906+ await prepareData ( url , {
907+ ignoreNetworkEvents : true ,
908+ } ) ;
909+ } ) ;
910+ afterEach ( ( ) => {
911+ clearData ( ) ;
912+ } ) ;
913+ it ( 'should NOT add network events' , ( ) => {
914+ const span : tracing . ReadableSpan = exportSpy . args [ 1 ] [ 0 ] [ 0 ] ;
915+ const events = span . events ;
916+ assert . strictEqual ( events . length , 0 , 'number of events is wrong' ) ;
917+ } ) ;
918+ } ) ;
903919} ) ;
You can’t perform that action at this time.
0 commit comments