Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(instr-cucumber): use exported strings for attributes #2143

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

13 changes: 13 additions & 0 deletions plugins/node/instrumentation-cucumber/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,19 @@ Cucumber instrumentation has currently no options.
| Options | Type | Description |
| ------- | ---- | ----------- |

## 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 |
| ---------------- | -------------------------------------------------------------------------------- |
| `code.filepath` | The source code file name that identifies the code unit as uniquely as possible. |
| `code.function` | The method or function name, or equivalent. |
| `code.lineno` | The line number in `code.filepath` best representing the operation. |
| `code.namespace` | The "namespace" within which `code.function` is defined. |

## Useful links

- For more information on OpenTelemetry, visit: <https://opentelemetry.io/>
Expand Down
2 changes: 1 addition & 1 deletion plugins/node/instrumentation-cucumber/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
},
"dependencies": {
"@opentelemetry/instrumentation": "^0.51.0",
"@opentelemetry/semantic-conventions": "^1.0.0"
"@opentelemetry/semantic-conventions": "^1.22.0"
},
"homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/instrumentation-cucumber#readme"
}
15 changes: 10 additions & 5 deletions plugins/node/instrumentation-cucumber/src/instrumentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ import {
InstrumentationNodeModuleFile,
isWrapped,
} from '@opentelemetry/instrumentation';
import { SemanticAttributes } from '@opentelemetry/semantic-conventions';
import {
SEMATTRS_CODE_FILEPATH,
SEMATTRS_CODE_FUNCTION,
SEMATTRS_CODE_LINENO,
SEMATTRS_CODE_NAMESPACE,
} from '@opentelemetry/semantic-conventions';

import type * as cucumber from '@cucumber/cucumber';
import type * as messages from '@cucumber/messages';
Expand Down Expand Up @@ -174,10 +179,10 @@ export class CucumberInstrumentation extends InstrumentationBase {
{
kind: SpanKind.CLIENT,
attributes: {
[SemanticAttributes.CODE_FILEPATH]: gherkinDocument.uri,
[SemanticAttributes.CODE_LINENO]: scenario.location.line,
[SemanticAttributes.CODE_FUNCTION]: scenario.name,
[SemanticAttributes.CODE_NAMESPACE]: feature.name,
[SEMATTRS_CODE_FILEPATH]: gherkinDocument.uri,
[SEMATTRS_CODE_LINENO]: scenario.location.line,
[SEMATTRS_CODE_FUNCTION]: scenario.name,
[SEMATTRS_CODE_NAMESPACE]: feature.name,
[AttributeNames.FEATURE_TAGS]: CucumberInstrumentation.mapTags(
feature.tags
),
Expand Down
19 changes: 12 additions & 7 deletions plugins/node/instrumentation-cucumber/test/cucumber.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,14 @@ import {
InMemorySpanExporter,
SimpleSpanProcessor,
} from '@opentelemetry/sdk-trace-base';
import { SemanticAttributes } from '@opentelemetry/semantic-conventions';
import {
SEMATTRS_CODE_FILEPATH,
SEMATTRS_CODE_FUNCTION,
SEMATTRS_CODE_LINENO,
SEMATTRS_CODE_NAMESPACE,
SEMRESATTRS_SERVICE_NAME,
} from '@opentelemetry/semantic-conventions';
import { Resource } from '@opentelemetry/resources';
import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';

import * as path from 'path';
import * as assert from 'assert';
Expand All @@ -50,7 +55,7 @@ import { PassThrough } from 'stream';
describe('CucumberInstrumentation', () => {
const provider = new NodeTracerProvider({
resource: new Resource({
[SemanticResourceAttributes.SERVICE_NAME]: 'CucumberInstrumentation',
[SEMRESATTRS_SERVICE_NAME]: 'CucumberInstrumentation',
}),
});
const memoryExporter = new InMemorySpanExporter();
Expand Down Expand Up @@ -165,10 +170,10 @@ describe('CucumberInstrumentation', () => {
assert(parent, 'Expected a parent span');

assert.deepEqual(parent.attributes, {
[SemanticAttributes.CODE_FILEPATH]: 'test/current.feature',
[SemanticAttributes.CODE_LINENO]: 7,
[SemanticAttributes.CODE_FUNCTION]: 'Button pushing',
[SemanticAttributes.CODE_NAMESPACE]: 'Basic',
[SEMATTRS_CODE_FILEPATH]: 'test/current.feature',
[SEMATTRS_CODE_LINENO]: 7,
[SEMATTRS_CODE_FUNCTION]: 'Button pushing',
[SEMATTRS_CODE_NAMESPACE]: 'Basic',
[AttributeNames.FEATURE_DESCRIPTION]:
' A very basic feature file with a single scenario',
[AttributeNames.FEATURE_LANGUAGE]: 'en',
Expand Down
Loading