mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-18 20:47:54 +00:00
add opentelemetr logging
This commit is contained in:
@@ -3,6 +3,7 @@ import { WebTracerProvider } from '@opentelemetry/sdk-trace-web';
|
||||
import { ZipkinExporter } from '@opentelemetry/exporter-zipkin';
|
||||
import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions'
|
||||
import { Resource } from '@opentelemetry/resources';
|
||||
import { context, trace, propagation } from '@opentelemetry/api';
|
||||
|
||||
function createProvider(serviceName) {
|
||||
const provider = new WebTracerProvider({
|
||||
@@ -32,3 +33,55 @@ export const OpentelemetryAgendaProvider = createProvider('FO-agenda-service');
|
||||
export const OpentelemetryNotificationProvider = createProvider('FO-notification');
|
||||
export const OpentelemetryInterceptorProvider = createProvider('FO-interceptor');
|
||||
export const OpentelemetryPublicationProvider = createProvider('FO-publication-service');
|
||||
export const OpentelemetryLogging = createProvider('logging');
|
||||
|
||||
|
||||
const tracerInstance = OpentelemetryAgendaProvider.getTracer('example-tracer-hole', '111', {})
|
||||
|
||||
|
||||
function parentSpanExample() {
|
||||
// Create a tracer instance
|
||||
const tracer = trace.getTracer('FO-chat-service');
|
||||
|
||||
// Start a parent span
|
||||
const parentSpan = tracer.startSpan('parent-span');
|
||||
parentSpan.setAttribute('key', 'value')
|
||||
|
||||
const traceId = parentSpan.spanContext().traceId;
|
||||
const spanId = parentSpan.spanContext().spanId;
|
||||
parentSpan.end(); // End the parent span
|
||||
|
||||
const spanContext = {
|
||||
traceId: traceId,
|
||||
spanId: spanId,
|
||||
traceFlags: 1 // 1 means the trace is sampled
|
||||
};
|
||||
|
||||
// Create a new context with the parent span
|
||||
const parentContext = trace.setSpan(context.active(), parentSpan);
|
||||
const parentContext1 = trace.setSpan(context.active(), trace.wrapSpanContext(spanContext));
|
||||
|
||||
// Start a new child span
|
||||
const childSpan = tracer.startSpan('child-span1', {root: false}, parentContext1);
|
||||
childSpan.end();
|
||||
|
||||
// Simulate some work
|
||||
setTimeout(() => {
|
||||
childSpanExample(parentContext); // Pass the context to child span
|
||||
|
||||
}, 500);
|
||||
}
|
||||
|
||||
|
||||
function childSpanExample(parentContext) {
|
||||
// Create a new child span with the parent context
|
||||
const tracer = trace.getTracer('FO-chat-service');
|
||||
const childSpan = tracer.startSpan('child-span', undefined, parentContext);
|
||||
|
||||
// Simulate some work
|
||||
setTimeout(() => {
|
||||
childSpan.end(); // End the child span
|
||||
}, 500);
|
||||
}
|
||||
|
||||
parentSpanExample()
|
||||
|
||||
Reference in New Issue
Block a user