How to use the @opentelemetry/api-logs package? #3652
Answered
by
Flarna
abhemanyus
asked this question in
Q&A
-
I am trying to use opentelemetry to collect logs as well as traces. I've got the latter working, but not the former. tracing.ts import process from 'process';
import { NodeSDK } from '@opentelemetry/sdk-node';
import { getNodeAutoInstrumentations } from '@opentelemetry/auto-instrumentations-node';
// import { ConsoleSpanExporter } from '@opentelemetry/sdk-trace-base';
import { Resource } from '@opentelemetry/resources';
import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';
import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-http";
import { diag, DiagConsoleLogger, DiagLogLevel } from "@opentelemetry/api";
import {logs} from "@opentelemetry/api-logs";
import { ARU_INSTANCE } from "./constants";
const resource = new Resource({
[SemanticResourceAttributes.SERVICE_NAME]: ARU_INSTANCE
})
diag.setLogger(new DiagConsoleLogger(), DiagLogLevel.INFO);
logs.setGlobalLoggerProvider(new DiagConsoleLogger());
// configure the SDK to export telemetry data to the console
// enable all auto-instrumentations from the meta package
// const traceExporter = new ConsoleSpanExporter();
const traceExporter = new OTLPTraceExporter({
url: "http://172.17.0.1:4318/v1/traces"
});
const sdk = new NodeSDK({
resource: resource,
traceExporter,
instrumentations: [getNodeAutoInstrumentations()]
});
// initialize the SDK and register with the OpenTelemetry API
// this enables the API to record telemetry
sdk.start();
// gracefully shut down the SDK on process exit
process.on('SIGTERM', () => {
sdk.shutdown()
.then(() => console.log('Tracing terminated'))
.catch((error) => console.log('Error terminating tracing', error))
.finally(() => process.exit(0));
}); |
Beta Was this translation helpful? Give feedback.
Answered by
Flarna
Mar 3, 2023
Replies: 1 comment 5 replies
-
The logs feature is not implemented in SDK yet, only the API. So as of now it's a dummy implementation. see e.g. #3549 regarding ongoing work for Logs SDK. |
Beta Was this translation helpful? Give feedback.
5 replies
Answer selected by
abhemanyus
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The logs feature is not implemented in SDK yet, only the API. So as of now it's a dummy implementation.
see e.g. #3549 regarding ongoing work for Logs SDK.