diff --git a/packages/opentelemetry-instrumentation-fetch/README.md b/packages/opentelemetry-instrumentation-fetch/README.md index 13bfec30e46..a18a364f343 100644 --- a/packages/opentelemetry-instrumentation-fetch/README.md +++ b/packages/opentelemetry-instrumentation-fetch/README.md @@ -59,6 +59,14 @@ fetch('http://localhost:8090/fetch.js'); See [examples/tracer-web/fetch](https://github.com/open-telemetry/opentelemetry-js/tree/main/examples/tracer-web) for a short example. +### Fetch Instrumentation options + +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/packages/opentelemetry-instrumentation-fetch/src/fetch.ts#L47) | `HttpCustomAttributeFunction` | Function for adding custom attributes | + ## Useful links - For more information on OpenTelemetry, visit: diff --git a/packages/opentelemetry-instrumentation-fetch/src/fetch.ts b/packages/opentelemetry-instrumentation-fetch/src/fetch.ts index 6bb40800de7..c843e7c6579 100644 --- a/packages/opentelemetry-instrumentation-fetch/src/fetch.ts +++ b/packages/opentelemetry-instrumentation-fetch/src/fetch.ts @@ -198,7 +198,7 @@ export class FetchInstrumentation extends InstrumentationBase< } const method = (options.method || 'GET').toUpperCase(); const spanName = `HTTP ${method}`; - const span = this.tracer.startSpan(spanName, { + return this.tracer.startSpan(spanName, { kind: api.SpanKind.CLIENT, attributes: { [AttributeNames.COMPONENT]: this.moduleName, @@ -206,8 +206,6 @@ export class FetchInstrumentation extends InstrumentationBase< [HttpAttribute.HTTP_URL]: url, }, }); - - return span; } /** @@ -320,7 +318,6 @@ export class FetchInstrumentation extends InstrumentationBase< ) { try { plugin._applyAttributesAfterFetch(span, options, response); - if (response.status >= 200 && response.status < 400) { plugin._endSpan(span, spanData, response); } else {