parent
49637552ac
commit
d80eb04f94
|
@ -0,0 +1,21 @@
|
||||||
|
description = 'OpenTelemetry - Logging Exporter'
|
||||||
|
|
||||||
|
buildscript {
|
||||||
|
repositories {
|
||||||
|
maven { url "https://plugins.gradle.org/m2/" }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
api project(':opentelemetry-sdk')
|
||||||
|
|
||||||
|
signature "org.codehaus.mojo.signature:java17:1.0@signature"
|
||||||
|
signature "net.sf.androidscents.signature:android-api-level-14:4.0_r4@signature"
|
||||||
|
}
|
||||||
|
|
||||||
|
animalsniffer {
|
||||||
|
// Don't check sourceSets.jmh and sourceSets.test
|
||||||
|
sourceSets = [
|
||||||
|
sourceSets.main
|
||||||
|
]
|
||||||
|
}
|
|
@ -0,0 +1,38 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2019, OpenTelemetry Authors
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.opentelemetry.exporters.logging;
|
||||||
|
|
||||||
|
import io.opentelemetry.sdk.trace.SpanData;
|
||||||
|
import io.opentelemetry.sdk.trace.export.SpanExporter;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
/** A Span Exporter that logs every span at INFO level using java.util.logging. */
|
||||||
|
public class LoggingExporter implements SpanExporter {
|
||||||
|
private static final Logger logger = Logger.getLogger(LoggingExporter.class.getName());
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ResultCode export(List<SpanData> spans) {
|
||||||
|
for (SpanData span : spans) {
|
||||||
|
logger.info("span: " + span);
|
||||||
|
}
|
||||||
|
return ResultCode.SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void shutdown() {}
|
||||||
|
}
|
|
@ -0,0 +1,60 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2019, OpenTelemetry Authors
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.opentelemetry.exporters.logging;
|
||||||
|
|
||||||
|
import static java.util.Collections.singletonList;
|
||||||
|
import static java.util.Collections.singletonMap;
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
|
import io.opentelemetry.common.Timestamp;
|
||||||
|
import io.opentelemetry.sdk.trace.SpanData;
|
||||||
|
import io.opentelemetry.sdk.trace.export.SpanExporter.ResultCode;
|
||||||
|
import io.opentelemetry.trace.AttributeValue;
|
||||||
|
import io.opentelemetry.trace.Span.Kind;
|
||||||
|
import io.opentelemetry.trace.SpanId;
|
||||||
|
import io.opentelemetry.trace.Status;
|
||||||
|
import io.opentelemetry.trace.TraceId;
|
||||||
|
import io.opentelemetry.trace.util.Events;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class LoggingExporterTest {
|
||||||
|
@Test
|
||||||
|
public void returnCode() throws Exception {
|
||||||
|
LoggingExporter exporter = new LoggingExporter();
|
||||||
|
long startTimeSecondsSinceEpoch = System.currentTimeMillis() / 1000;
|
||||||
|
SpanData spanData =
|
||||||
|
SpanData.newBuilder()
|
||||||
|
.setTraceId(new TraceId(1234L, 6789L))
|
||||||
|
.setSpanId(new SpanId(9876L))
|
||||||
|
.setStartTimestamp(Timestamp.create(startTimeSecondsSinceEpoch, 0))
|
||||||
|
.setEndTimestamp(Timestamp.create(startTimeSecondsSinceEpoch, 100))
|
||||||
|
.setStatus(Status.OK)
|
||||||
|
.setName("testSpan")
|
||||||
|
.setKind(Kind.INTERNAL)
|
||||||
|
.setTimedEvents(
|
||||||
|
singletonList(
|
||||||
|
SpanData.TimedEvent.create(
|
||||||
|
Timestamp.create(startTimeSecondsSinceEpoch, 50),
|
||||||
|
Events.create(
|
||||||
|
"somethingHappenedHere",
|
||||||
|
singletonMap(
|
||||||
|
"important", AttributeValue.booleanAttributeValue(true))))))
|
||||||
|
.build();
|
||||||
|
ResultCode resultCode = exporter.export(singletonList(spanData));
|
||||||
|
assertEquals(ResultCode.SUCCESS, resultCode);
|
||||||
|
}
|
||||||
|
}
|
|
@ -5,6 +5,7 @@ include ":opentelemetry-api"
|
||||||
include ":opentelemetry-contrib-runtime-metrics"
|
include ":opentelemetry-contrib-runtime-metrics"
|
||||||
include ":opentelemetry-contrib-trace-utils"
|
include ":opentelemetry-contrib-trace-utils"
|
||||||
include ":opentelemetry-exporters-jaeger"
|
include ":opentelemetry-exporters-jaeger"
|
||||||
|
include ":opentelemetry-exporters-logging"
|
||||||
include ":opentelemetry-opentracing-shim"
|
include ":opentelemetry-opentracing-shim"
|
||||||
include ":opentelemetry-proto"
|
include ":opentelemetry-proto"
|
||||||
include ":opentelemetry-sdk"
|
include ":opentelemetry-sdk"
|
||||||
|
@ -19,6 +20,7 @@ project(':opentelemetry-contrib-runtime-metrics').projectDir =
|
||||||
"$rootDir/contrib/runtime_metrics" as File
|
"$rootDir/contrib/runtime_metrics" as File
|
||||||
project(':opentelemetry-contrib-trace-utils').projectDir = "$rootDir/contrib/trace_utils" as File
|
project(':opentelemetry-contrib-trace-utils').projectDir = "$rootDir/contrib/trace_utils" as File
|
||||||
project(':opentelemetry-exporters-jaeger').projectDir = "$rootDir/exporters/jaeger" as File
|
project(':opentelemetry-exporters-jaeger').projectDir = "$rootDir/exporters/jaeger" as File
|
||||||
|
project(':opentelemetry-exporters-logging').projectDir = "$rootDir/exporters/logging" as File
|
||||||
project(':opentelemetry-opentracing-shim').projectDir = "$rootDir/opentracing_shim" as File
|
project(':opentelemetry-opentracing-shim').projectDir = "$rootDir/opentracing_shim" as File
|
||||||
project(':opentelemetry-sdk').projectDir = "$rootDir/sdk" as File
|
project(':opentelemetry-sdk').projectDir = "$rootDir/sdk" as File
|
||||||
project(':opentelemetry-sdk-contrib-async-processor').projectDir =
|
project(':opentelemetry-sdk-contrib-async-processor').projectDir =
|
||||||
|
|
Loading…
Reference in New Issue