NodeJS
Send traces to aspecto directly from your code using exporter-trace-otlp-proto . Here is an example Node.js TypeScript and JavaScript snippets:
Type Script
Java Script
1
import { NodeTracerProvider } from '@opentelemetry/sdk-trace-node';
2
import { Resource } from '@opentelemetry/resources';
3
import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';
4
import { SimpleSpanProcessor } from '@opentelemetry/sdk-trace-base';
5
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-proto';
6
import { registerInstrumentations } from '@opentelemetry/instrumentation';
7
​
8
const provider = new NodeTracerProvider({
9
resource: new Resource({
10
[SemanticResourceAttributes.SERVICE_NAME]: 'my-service-name' // service name is required
11
}),
12
});
13
​
14
provider.register();
15
provider.addSpanProcessor(
16
new SimpleSpanProcessor(
17
new OTLPTraceExporter({
18
url: 'https://otelcol.aspecto.io/v1/traces',
19
headers: {
20
// Aspecto API-Key is required
21
Authorization: process.env.ASPECTO_API_KEY
22
}
23
})
24
)
25
);
26
​
27
registerInstrumentations({
28
instrumentations: [
29
// add auto instrumentations here for packages your app uses
30
],
31
});
Copied!
1
const { NodeTracerProvider } = require('@opentelemetry/sdk-trace-node');
2
const { Resource } = require('@opentelemetry/resources');
3
const { SemanticResourceAttributes } = require('@opentelemetry/semantic-conventions');
4
const { SimpleSpanProcessor } = require('@opentelemetry/sdk-trace-base');
5
const { OTLPTraceExporter } = require('@opentelemetry/exporter-trace-otlp-proto');
6
​
7
const provider = new NodeTracerProvider({
8
resource: new Resource({
9
[SemanticResourceAttributes.SERVICE_NAME]: 'my-service-name' // service name is required
10
}),
11
});
12
​
13
provider.register();
14
provider.addSpanProcessor(
15
new SimpleSpanProcessor(
16
new OTLPTraceExporter({
17
url: 'https://otelcol.aspecto.io/v1/traces',
18
headers: {
19
// Aspecto API-Key is required
20
Authorization: process.env.ASPECTO_API_KEY
21
}
22
})
23
)
24
);
25
​
Copied!
​
Copy link