Skip to content

Commit

Permalink
use devnull exporter
Browse files Browse the repository at this point in the history
  • Loading branch information
suranjay committed Jul 20, 2023
1 parent 1aa5e91 commit 3748ee6
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/

package org.opensearch.telemetry.tracing;

import io.opentelemetry.sdk.common.CompletableResultCode;
import io.opentelemetry.sdk.common.InstrumentationScopeInfo;
import io.opentelemetry.sdk.trace.data.SpanData;
import io.opentelemetry.sdk.trace.export.SpanExporter;
import java.util.Collection;
import java.util.concurrent.atomic.AtomicBoolean;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

/**
* Writes the span to a log file. This is mostly for testing where you can trace one request and all your spans
* will be written to a file. Tracing log file would be available in the logs directory.
*/
public class FileSpanExporter implements SpanExporter {
/**
* jfkdfj
*/
public static final String TRACING_LOG_PREFIX = "tracing_log";
private static final Logger TRACING_LOGGER = LogManager.getLogger(TRACING_LOG_PREFIX);
private final Logger DEFAULT_LOGGER = LogManager.getLogger(FileSpanExporter.class);
private final String FIELD_SEPARATOR = "\t";

private final AtomicBoolean isShutdown = new AtomicBoolean();

/**
* fjkdjf
*/
public FileSpanExporter() {
}

@Override
public CompletableResultCode export(Collection<SpanData> spans) {
if (isShutdown.get()) {
return CompletableResultCode.ofFailure();
}
StringBuilder sb = new StringBuilder(128);
for (SpanData span : spans) {
sb.setLength(0);
InstrumentationScopeInfo instrumentationScopeInfo = span.getInstrumentationScopeInfo();
sb.append("'")
.append(span.getName())
.append("'")
.append(FIELD_SEPARATOR)
.append(span.getTraceId())
.append(FIELD_SEPARATOR)
.append(span.getSpanId())
.append(FIELD_SEPARATOR)
.append(span.getParentSpanId())
.append(FIELD_SEPARATOR)
.append(span.getKind())
.append(FIELD_SEPARATOR)
.append(span.getStartEpochNanos())
.append(FIELD_SEPARATOR)
.append(span.getEndEpochNanos())
.append(FIELD_SEPARATOR)
.append("[tracer:")
.append(instrumentationScopeInfo.getName())
.append(":")
.append(instrumentationScopeInfo.getVersion() == null ? "" : instrumentationScopeInfo.getVersion())
.append("]")
.append(FIELD_SEPARATOR)
.append(span.getAttributes());
// TRACING_LOGGER.info(sb.toString());
}
return CompletableResultCode.ofSuccess();
}

@Override
public CompletableResultCode flush() {
return CompletableResultCode.ofSuccess();
}

@Override
public CompletableResultCode shutdown() {
if (!isShutdown.compareAndSet(false, true)) {
DEFAULT_LOGGER.info("Duplicate shutdown() calls.");
}
return CompletableResultCode.ofSuccess();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ private OTelResourceProvider() {}
public static OpenTelemetry get(Settings settings) {
return get(
settings,
new LoggingSpanExporter(),
new FileSpanExporter(),
ContextPropagators.create(W3CTraceContextPropagator.getInstance()),
Sampler.alwaysOn()
);
Expand Down

0 comments on commit 3748ee6

Please sign in to comment.