Skip to content

Commit

Permalink
docs(instrumentation-fetch): document applyCustomAttributesOnSpan
Browse files Browse the repository at this point in the history
  • Loading branch information
niekert committed Apr 2, 2021
1 parent 611f475 commit 5423518
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
8 changes: 8 additions & 0 deletions packages/opentelemetry-instrumentation-fetch/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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: <https://opentelemetry.io/>
Expand Down
5 changes: 1 addition & 4 deletions packages/opentelemetry-instrumentation-fetch/src/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,16 +198,14 @@ 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,
[HttpAttribute.HTTP_METHOD]: method,
[HttpAttribute.HTTP_URL]: url,
},
});

return span;
}

/**
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 5423518

Please sign in to comment.