Skip to content

Commit

Permalink
refactor(instr-connect): use exported strings for attributes (#2154)
Browse files Browse the repository at this point in the history
Co-authored-by: Amir Blum <amirgiraffe@gmail.com>
  • Loading branch information
david-luna and blumamir committed May 2, 2024
1 parent 695177b commit 16f920a
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 9 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions plugins/node/opentelemetry-instrumentation-connect/README.md
Expand Up @@ -51,6 +51,16 @@ registerInstrumentations({

See [examples/connect](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/examples/connect) for a short example.

## Semantic Conventions

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)

Attributes collected:

| Attribute | Short Description |
| ------------ | ---------------------------------- |
| `http.route` | The matched route (path template). |

## Useful links

- For more information on OpenTelemetry, visit: <https://opentelemetry.io/>
Expand Down
Expand Up @@ -57,7 +57,7 @@
"dependencies": {
"@opentelemetry/core": "^1.8.0",
"@opentelemetry/instrumentation": "^0.51.0",
"@opentelemetry/semantic-conventions": "^1.0.0",
"@opentelemetry/semantic-conventions": "^1.22.0",
"@types/connect": "3.4.36"
},
"homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-connect#readme"
Expand Down
Expand Up @@ -31,7 +31,7 @@ import {
InstrumentationNodeModuleDefinition,
isWrapped,
} from '@opentelemetry/instrumentation';
import { SemanticAttributes } from '@opentelemetry/semantic-conventions';
import { SEMATTRS_HTTP_ROUTE } from '@opentelemetry/semantic-conventions';
import {
replaceCurrentStackRoute,
addNewStackLayer,
Expand Down Expand Up @@ -100,7 +100,7 @@ export class ConnectInstrumentation extends InstrumentationBase {
const spanName = `${connectTypeName} - ${connectName}`;
const options: SpanOptions = {
attributes: {
[SemanticAttributes.HTTP_ROUTE]: routeName.length > 0 ? routeName : '/',
[SEMATTRS_HTTP_ROUTE]: routeName.length > 0 ? routeName : '/',
[AttributeNames.CONNECT_TYPE]: connectType,
[AttributeNames.CONNECT_NAME]: connectName,
},
Expand Down
Expand Up @@ -17,7 +17,7 @@ import * as assert from 'assert';

import { context, trace } from '@opentelemetry/api';
import { RPCType, setRPCMetadata, RPCMetadata } from '@opentelemetry/core';
import { SemanticAttributes } from '@opentelemetry/semantic-conventions';
import { SEMATTRS_HTTP_ROUTE } from '@opentelemetry/semantic-conventions';
import { AsyncHooksContextManager } from '@opentelemetry/context-async-hooks';
import { NodeTracerProvider } from '@opentelemetry/sdk-trace-node';
import {
Expand Down Expand Up @@ -144,7 +144,7 @@ describe('connect', () => {
assert.deepStrictEqual(span.attributes, {
'connect.type': 'middleware',
'connect.name': ANONYMOUS_NAME,
[SemanticAttributes.HTTP_ROUTE]: '/',
[SEMATTRS_HTTP_ROUTE]: '/',
});
assert.strictEqual(span.name, 'middleware - anonymous');
});
Expand All @@ -163,7 +163,7 @@ describe('connect', () => {
assert.deepStrictEqual(span.attributes, {
'connect.type': 'middleware',
'connect.name': 'middleware1',
[SemanticAttributes.HTTP_ROUTE]: '/',
[SEMATTRS_HTTP_ROUTE]: '/',
});
assert.strictEqual(span.name, 'middleware - middleware1');
});
Expand All @@ -181,7 +181,7 @@ describe('connect', () => {
assert.deepStrictEqual(span.attributes, {
'connect.type': 'request_handler',
'connect.name': '/foo',
[SemanticAttributes.HTTP_ROUTE]: '/foo',
[SEMATTRS_HTTP_ROUTE]: '/foo',
});
assert.strictEqual(span.name, 'request handler - /foo');
});
Expand Down

0 comments on commit 16f920a

Please sign in to comment.