|
3 | 3 | [![NPM Published Version][npm-img]][npm-url] |
4 | 4 | [![Apache License][license-image]][license-image] |
5 | 5 |
|
6 | | -**Note: This is an experimental package under active development. New releases may include breaking changes.** |
| 6 | +**Note: This is an experimental package. New releases may include breaking changes.** |
7 | 7 |
|
8 | | -This module provides auto instrumentation for web using XMLHttpRequest . |
| 8 | +This module provides auto instrumentation for web using XMLHttpRequest. |
9 | 9 |
|
10 | 10 | ## Installation |
11 | 11 |
|
@@ -62,34 +62,48 @@ xmlHttpRequestInstrumentation.setTracerProvider(providerWithZone); |
62 | 62 | const req = new XMLHttpRequest(); |
63 | 63 | req.open('GET', 'http://localhost:8090/xml-http-request.js', true); |
64 | 64 | req.send(); |
65 | | - |
66 | 65 | ``` |
67 | 66 |
|
68 | 67 | ### XHR Instrumentation options |
69 | 68 |
|
70 | 69 | XHR instrumentation plugin has few options available to choose from. You can set the following: |
71 | 70 |
|
72 | | -| Options | Type | Description | |
73 | | -|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------|-----------------------------------------------------------------------------------------| |
74 | | -| [`applyCustomAttributesOnSpan`](https://github.com/open-telemetry/opentelemetry-js/blob/main/experimental/packages/opentelemetry-instrumentation-xml-http-request/src/xhr.ts#L85) | `XHRCustomAttributeFunction` | Function for adding custom attributes | |
75 | | -| [`ignoreNetworkEvents`](https://github.com/open-telemetry/opentelemetry-js/blob/main/experimental/packages/opentelemetry-instrumentation-xml-http-request/src/xhr.ts#L87) | `boolean` | Disable network events being added as span events (network events are added by default) | |
76 | | -| [`measureRequestSize`](https://github.com/open-telemetry/opentelemetry-js/blob/main/experimental/packages/opentelemetry-instrumentation-xml-http-request/src/xhr.ts#L89) | `boolean` | Measure outgoing request length (outgoing request length is not measured by default) | |
| 71 | +| Options | Type | Description | |
| 72 | +| ----------------------------- | ---------------------------- | ----------- | |
| 73 | +| `applyCustomAttributesOnSpan` | `XHRCustomAttributeFunction` | Function for adding custom attributes | |
| 74 | +| `ignoreNetworkEvents` | boolean | Disable network events being added as span events (network events are added by default) | |
| 75 | +| `measureRequestSize` | boolean | Measure outgoing request length (outgoing request length is not measured by default) | |
| 76 | +| `semconvStabilityOptIn` | string | A comma-separated string of tokens as described for `OTEL_SEMCONV_STABILITY_OPT_IN` in the [HTTP semantic convention stability migration](https://github.com/open-telemetry/semantic-conventions/blob/main/docs/non-normative/http-migration.md) guide. See the "Semantic Conventions" section below. | |
77 | 77 |
|
78 | 78 | ## Semantic Conventions |
79 | 79 |
|
80 | | -This package uses `@opentelemetry/semantic-conventions` version `1.22+`, which implements Semantic Convention [Version 1.7.0](https://github.com/open-telemetry/opentelemetry-specification/blob/v1.7.0/semantic_conventions/README.md) |
| 80 | +Up to and including v0.200.0, `instrumentation-xml-http-request` generates telemetry using [Semantic Conventions v1.7.0](https://github.com/open-telemetry/opentelemetry-specification/blob/v1.7.0/semantic_conventions/README.md). |
| 81 | + |
| 82 | +HTTP semantic conventions (semconv) were stabilized in semconv v1.23.0, and a [migration process](https://github.com/open-telemetry/semantic-conventions/blob/main/docs/non-normative/http-migration.md#http-semantic-convention-stability-migration) was defined. `instrumentation-xml-http-request` versions 0.201.0 and later include support for migrating to stable HTTP semantic conventions, as described below. The intent is to provide an approximate 6 month time window for users of this instrumentation to migrate to the new HTTP semconv, after which a new minor version will change to use the *new* semconv by default and drop support for the old semconv. See the [HTTP semconv migration plan for OpenTelemetry JS instrumentations](https://github.com/open-telemetry/opentelemetry-js/issues/5646). |
| 83 | + |
| 84 | +To select which semconv version(s) is emitted from this instrumentation, use the `semconvStabilityOptIn` configuration option. This option works [as described for `OTEL_SEMCONV_STABILITY_OPT_IN`](https://github.com/open-telemetry/semantic-conventions/blob/main/docs/non-normative/http-migration.md): |
| 85 | + |
| 86 | +- `http`: emit the new (stable) v1.23.0 semantics |
| 87 | +- `http/dup`: emit **both** the old v1.7.0 and the new (stable) v1.23.0 semantics |
| 88 | +- By default, if `semconvStabilityOptIn` includes neither of the above tokens, the old v1.7.0 semconv is used. |
| 89 | + |
| 90 | +**Span status:** When the stable semconv is selected, the [span status](https://github.com/open-telemetry/semantic-conventions/blob/main/docs/http/http-spans.md#status) is set to ERROR when the response status code is `>=400` or when the response fails with an 'error' or 'timeout' XHR event. When just the old semconv is select, the span status is not set. |
81 | 91 |
|
82 | | -Attributes collected: |
| 92 | +**Span attributes:** |
83 | 93 |
|
84 | | -| Attribute | Short Description | |
85 | | -| ------------------------------------------- | ------------------------------------------------------------------------------ | |
86 | | -| `http.status_code` | HTTP response status code | |
87 | | -| `http.host` | The value of the HTTP host header | |
88 | | -| `http.user_agent` | Value of the HTTP User-Agent header sent by the client | |
89 | | -| `http.scheme` | The URI scheme identifying the used protocol | |
90 | | -| `http.url` | Full HTTP request URL | |
91 | | -| `http.method` | HTTP request method | |
92 | | -| `http.request_content_length_uncompressed` | Uncompressed size of the request body, if any body exists | |
| 94 | +| v1.7.0 semconv | v1.23.0 semconv | Notes | |
| 95 | +| ---------------------- | ---------------------------------- | ----- | |
| 96 | +| `http.method` | `http.request.method` | HTTP request method. With v1.23.0 semconv [`http.request.method_original` may also be included](https://github.com/open-telemetry/semantic-conventions/blob/v1.23.1/docs/http/http-spans.md#common-attributes). | |
| 97 | +| `http.url` | `url.full` | Full HTTP request URL | |
| 98 | +| `http.host` | `server.address` and `server.port` | The hostname and port of the request URL | |
| 99 | +| `http.status_code` | `http.response.status_code` | HTTP response status code | |
| 100 | +| `http.request_content_length_uncompressed` | `http.request.body.size` | This is only added if `measureRequestSize` is `true`. | |
| 101 | +| `http.response_content_length_uncompressed` | (not included) | Stable HTTP semconv would use `http.response.body.size`, but this is an [`Opt-In` attribute](https://github.com/open-telemetry/semantic-conventions/blob/v1.23.1/docs/http/http-spans.md#http-client), so would require adding a configuration option to this instrumentation to enable. | |
| 102 | +| `http.response_content_length` | (not included) | Stable HTTP semconv would use `http.response.header.<key>`, but this is an [`Opt-In` attribute](https://github.com/open-telemetry/semantic-conventions/blob/v1.23.1/docs/http/http-spans.md#http-client), so would require adding a configuration option to this instrumentation to enable. | |
| 103 | +| (no equivalent) | `error.type` | The response status (as a string), if the response status was `>=400`, or one of these possible request errors: 'timeout' and 'error'.| |
| 104 | +| `http.user_agent` | (not included) | Stable HTTP semconv would use `user_agent.original`, but this is an [`Opt-In` attribute](https://github.com/open-telemetry/semantic-conventions/blob/v1.23.1/docs/http/http-spans.md#http-client), so would require adding a configuration option to this instrumentation to enable. | |
| 105 | +| `http.scheme` | (not included) | Stable HTTP semconv would use `url.scheme`, but this is an [`Opt-In` attribute](https://github.com/open-telemetry/semantic-conventions/blob/v1.23.1/docs/http/http-spans.md#http-client), so would require adding a configuration option to this instrumentation to enable. | |
| 106 | +| `http.status_text` | (not included) | This is no longer a documented semantic conventions attribute. | |
93 | 107 |
|
94 | 108 | ## Example Screenshots |
95 | 109 |
|
|
0 commit comments