From 5423518647350a5a11a1ca859f82aefabfed4844 Mon Sep 17 00:00:00 2001 From: Niek Kruse Date: Fri, 2 Apr 2021 10:03:28 +0200 Subject: [PATCH] docs(instrumentation-fetch): document applyCustomAttributesOnSpan --- packages/opentelemetry-instrumentation-fetch/README.md | 8 ++++++++ packages/opentelemetry-instrumentation-fetch/src/fetch.ts | 5 +---- 2 files changed, 9 insertions(+), 4 deletions(-) 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 {