Search in sources :

Example 1 with ZipkinSpanExporter

use of io.opentelemetry.exporter.zipkin.ZipkinSpanExporter in project java-sdk by dapr.

the class OpenTelemetryConfig method createOpenTelemetry.

/**
 * Creates an opentelemetry instance.
 * @return OpenTelemetry.
 */
public static OpenTelemetry createOpenTelemetry() {
    // This is helpful to avoid exceptions for examples that do not require Zipkin.
    if (isZipkinUp()) {
        String httpUrl = String.format("http://localhost:%d", ZIPKIN_PORT);
        ZipkinSpanExporter zipkinExporter = ZipkinSpanExporter.builder().setEndpoint(httpUrl + ENDPOINT_V2_SPANS).setServiceName(InvokeClient.class.getName()).build();
        SdkTracerProvider sdkTracerProvider = SdkTracerProvider.builder().addSpanProcessor(SimpleSpanProcessor.create(zipkinExporter)).build();
        return OpenTelemetrySdk.builder().setTracerProvider(sdkTracerProvider).setPropagators(ContextPropagators.create(W3CTraceContextPropagator.getInstance())).buildAndRegisterGlobal();
    } else {
        System.out.println("WARNING: Zipkin is not available.");
    }
    return null;
}
Also used : ZipkinSpanExporter(io.opentelemetry.exporter.zipkin.ZipkinSpanExporter) SdkTracerProvider(io.opentelemetry.sdk.trace.SdkTracerProvider)

Example 2 with ZipkinSpanExporter

use of io.opentelemetry.exporter.zipkin.ZipkinSpanExporter in project java-sdk by dapr.

the class OpenTelemetry method createOpenTelemetry.

/**
 * Creates an opentelemetry instance.
 * @param serviceName Name of the service in Zipkin
 * @return OpenTelemetry.
 */
public static io.opentelemetry.api.OpenTelemetry createOpenTelemetry(String serviceName) {
    // This is helpful to avoid exceptions for examples that do not require Zipkin.
    if (isZipkinUp()) {
        String httpUrl = String.format("http://localhost:%d", ZIPKIN_PORT);
        ZipkinSpanExporter zipkinExporter = ZipkinSpanExporter.builder().setEndpoint(httpUrl + ENDPOINT_V2_SPANS).setServiceName(serviceName).build();
        SdkTracerProvider sdkTracerProvider = SdkTracerProvider.builder().addSpanProcessor(SimpleSpanProcessor.create(zipkinExporter)).build();
        return OpenTelemetrySdk.builder().setTracerProvider(sdkTracerProvider).setPropagators(ContextPropagators.create(W3CTraceContextPropagator.getInstance())).buildAndRegisterGlobal();
    } else {
        System.out.println("WARNING: Zipkin is not available.");
    }
    return null;
}
Also used : ZipkinSpanExporter(io.opentelemetry.exporter.zipkin.ZipkinSpanExporter) SdkTracerProvider(io.opentelemetry.sdk.trace.SdkTracerProvider)

Example 3 with ZipkinSpanExporter

use of io.opentelemetry.exporter.zipkin.ZipkinSpanExporter in project incubator-eventmesh by apache.

the class ZipkinTraceService method init.

@Override
public void init() {
    // zipkin's config
    eventMeshZipkinIP = ZipkinConfiguration.getEventMeshZipkinIP();
    eventMeshZipkinPort = ZipkinConfiguration.getEventMeshZipkinPort();
    // exporter's config
    eventMeshTraceExportInterval = ExporterConfiguration.getEventMeshTraceExportInterval();
    eventMeshTraceExportTimeout = ExporterConfiguration.getEventMeshTraceExportTimeout();
    eventMeshTraceMaxExportSize = ExporterConfiguration.getEventMeshTraceMaxExportSize();
    eventMeshTraceMaxQueueSize = ExporterConfiguration.getEventMeshTraceMaxQueueSize();
    String httpUrl = String.format("http://%s:%s", eventMeshZipkinIP, eventMeshZipkinPort);
    ZipkinSpanExporter zipkinExporter = ZipkinSpanExporter.builder().setEndpoint(httpUrl + ENDPOINT_V2_SPANS).build();
    SpanProcessor spanProcessor = BatchSpanProcessor.builder(zipkinExporter).setScheduleDelay(eventMeshTraceExportInterval, TimeUnit.SECONDS).setExporterTimeout(eventMeshTraceExportTimeout, TimeUnit.SECONDS).setMaxExportBatchSize(eventMeshTraceMaxExportSize).setMaxQueueSize(eventMeshTraceMaxQueueSize).build();
    // set the trace service's name
    Resource serviceNameResource = Resource.create(Attributes.of(stringKey("service.name"), serviceName));
    sdkTracerProvider = SdkTracerProvider.builder().addSpanProcessor(spanProcessor).setResource(Resource.getDefault().merge(serviceNameResource)).build();
    openTelemetry = OpenTelemetrySdk.builder().setPropagators(ContextPropagators.create(W3CTraceContextPropagator.getInstance())).setTracerProvider(sdkTracerProvider).build();
    Runtime.getRuntime().addShutdownHook(new Thread(sdkTracerProvider::close));
}
Also used : BatchSpanProcessor(io.opentelemetry.sdk.trace.export.BatchSpanProcessor) SpanProcessor(io.opentelemetry.sdk.trace.SpanProcessor) Resource(io.opentelemetry.sdk.resources.Resource) ZipkinSpanExporter(io.opentelemetry.exporter.zipkin.ZipkinSpanExporter)

Aggregations

ZipkinSpanExporter (io.opentelemetry.exporter.zipkin.ZipkinSpanExporter)3 SdkTracerProvider (io.opentelemetry.sdk.trace.SdkTracerProvider)2 Resource (io.opentelemetry.sdk.resources.Resource)1 SpanProcessor (io.opentelemetry.sdk.trace.SpanProcessor)1 BatchSpanProcessor (io.opentelemetry.sdk.trace.export.BatchSpanProcessor)1