Open
Description
- This only affects the JavaScript OpenTelemetry library
- This may affect other libraries, but I would like to get opinions here first
I am trying to instrument my cucumber tests in NodeJS but I can't make it trace anything at all.
I tried using both
import { getNodeAutoInstrumentations } from '@opentelemetry/auto-instrumentations-node'
and
import { CucumberInstrumentation } from '@opentelemetry/instrumentation-cucumber'
but had no luck with either.
This is the file I have that sets up the telemetry:
/* eslint-disable @typescript-eslint/no-unused-vars */
import { After, Before, BeforeStep, AfterStep, Status, BeforeAll } from '@cucumber/cucumber'
import { NodeSDK } from '@opentelemetry/sdk-node'
import { CucumberInstrumentation } from '@opentelemetry/instrumentation-cucumber'
import { Resource } from '@opentelemetry/resources'
import { ATTR_SERVICE_NAME } from '@opentelemetry/semantic-conventions'
import * as api from '@opentelemetry/api'
import { AsyncHooksContextManager } from '@opentelemetry/context-async-hooks'
import * as grpc from '@grpc/grpc-js'
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-grpc'
const collectorOptions = {
url: 'localhost:4317',
credentials: grpc.credentials.createInsecure(),
}
const sdk = new NodeSDK({
resource: new Resource({
[ATTR_SERVICE_NAME]: 'E2E System Tests'
}),
traceExporter: new OTLPTraceExporter(collectorOptions),
instrumentations: [new CucumberInstrumentation()],
})
const contextManager = new AsyncHooksContextManager().enable()
api.context.setGlobalContextManager(contextManager)
try {
sdk.start()
console.log('Tracing initialized')
} catch (error) {
console.log('Error initializing tracing', error)
}
// Executed after all scenarios
AfterAll(function () {
sdk.shutdown()
.then(() => console.log('Tracing terminated'))
.catch((error) => console.log('Error terminating tracing', error))
})
It gets called and if I create spans manually they show up in the OTELCollector, so telemetry seems to be properly set up.
Does anyone have a real example of to set it up for a real cucumber project?