@opentelemetry/instrumentation-long-task
v0.69.0
Published
OpenTelemetry instrumentation for long task Web API
Readme
OpenTelemetry Long Task Instrumentation for web
This module provides automatic instrumentation for the Long Task API.
It creates spans from tasks that take more than 50 milliseconds.
All of the data reported via PerformanceLongTaskTiming is included as span attributes.
Installation
npm install --save @opentelemetry/instrumentation-long-taskUsage
import { ConsoleSpanExporter, SimpleSpanProcessor, TracerProvider } from '@opentelemetry/sdk-trace';
import { LongTaskInstrumentation } from '@opentelemetry/instrumentation-long-task';
import { registerInstrumentations } from '@opentelemetry/instrumentation';
const provider = new TracerProvider({
spanProcessors: [
new SimpleSpanProcessor({ exporter: new ConsoleSpanExporter() }),
],
});
registerInstrumentations({
tracerProvider: provider,
instrumentations: [
new LongTaskInstrumentation({
// see under for available configuration
}),
],
});longtask Instrumentation Options
| Options | Type | Description |
| --- | --- | --- |
| observerCallback | ObserverCallback | Callback executed on observed longtask, allowing additional attributes to be attached to the span. |
The observerCallback function is passed the created span and the longtask PerformanceEntry,
allowing the user to add custom attributes to the span with any logic.
For example, a web app with client-side routing can add contextual information on the current page,
even if the tracer was instantiated before navigation.
Usage Example:
longtaskInstrumentationConfig = {
observerCallback: (span, longtaskEvent) => {
span.setAttribute('location.pathname', window.location.pathname)
}
}Semantic Conventions
This package does not currently generate any attributes from semantic conventions.
Useful links
- For more information on OpenTelemetry, visit: https://opentelemetry.io/
- For more about OpenTelemetry JavaScript: https://github.com/open-telemetry/opentelemetry-js
- For help or feedback on this project, join us in GitHub Discussions
License
Apache 2.0 - See LICENSE for more information.
