Remove Event interface, and it's usage (#1733)
* Remove Event interface, and it's usage Based on the specification we are not required to expose this interface or have APIs that accept this interface. Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com> * Fix links to Event Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com> * Fix more javadocs references to Event Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
This commit is contained in:
parent
64c2b8cc65
commit
b78fbb31fa
|
|
@ -87,12 +87,6 @@ public final class DefaultSpan implements Span {
|
|||
@Override
|
||||
public void addEvent(String name, Attributes attributes, long timestamp) {}
|
||||
|
||||
@Override
|
||||
public void addEvent(Event event) {}
|
||||
|
||||
@Override
|
||||
public void addEvent(Event event, long timestamp) {}
|
||||
|
||||
@Override
|
||||
public void setStatus(Status status) {}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,44 +0,0 @@
|
|||
/*
|
||||
* 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.trace;
|
||||
|
||||
import io.opentelemetry.common.Attributes;
|
||||
import javax.annotation.concurrent.ThreadSafe;
|
||||
|
||||
/**
|
||||
* A text annotation with a set of attributes.
|
||||
*
|
||||
* @since 0.1.0
|
||||
*/
|
||||
@ThreadSafe
|
||||
public interface Event {
|
||||
/**
|
||||
* Return the name of the {@code Event}.
|
||||
*
|
||||
* @return the name of the {@code Event}.
|
||||
* @since 0.1.0
|
||||
*/
|
||||
String getName();
|
||||
|
||||
/**
|
||||
* Return the attributes of the {@code Event}.
|
||||
*
|
||||
* @return the attributes of the {@code Event}.
|
||||
* @since 0.1.0
|
||||
*/
|
||||
Attributes getAttributes();
|
||||
}
|
||||
|
|
@ -161,7 +161,7 @@ public interface Span {
|
|||
}
|
||||
|
||||
/**
|
||||
* Adds an event to the {@link Span}. The timestamp of the {@link Event} will be the current time.
|
||||
* Adds an event to the {@link Span}. The timestamp of the event will be the current time.
|
||||
*
|
||||
* @param name the name of the event.
|
||||
* @since 0.1.0
|
||||
|
|
@ -184,8 +184,8 @@ public interface Span {
|
|||
void addEvent(String name, long timestamp);
|
||||
|
||||
/**
|
||||
* Adds an event to the {@link Span} with the given {@link Attributes}. The timestamp of the *
|
||||
* {@link Event} will be the current time.
|
||||
* Adds an event to the {@link Span} with the given {@link Attributes}. The timestamp of the event
|
||||
* will be the current time.
|
||||
*
|
||||
* @param name the name of the event.
|
||||
* @param attributes the attributes that will be added; these are associated with this event, not
|
||||
|
|
@ -211,29 +211,6 @@ public interface Span {
|
|||
*/
|
||||
void addEvent(String name, Attributes attributes, long timestamp);
|
||||
|
||||
/**
|
||||
* Adds an event to the {@link Span}. The timestamp of the {@link Event} will be the current time.
|
||||
*
|
||||
* @param event the event to add.
|
||||
* @since 0.1.0
|
||||
*/
|
||||
void addEvent(Event event);
|
||||
|
||||
/**
|
||||
* Adds an event to the {@link Span} with the given {@code timestamp}, as nanos since epoch. Note,
|
||||
* this {@code timestamp} is not the same as {@link System#nanoTime()} but may be computed using
|
||||
* it, for example, by taking a difference of readings from {@link System#nanoTime()} and adding
|
||||
* to the span start time.
|
||||
*
|
||||
* <p>When possible, it is preferred to use {@link #addEvent(String)} at the time the event
|
||||
* occurred.
|
||||
*
|
||||
* @param event the event to add.
|
||||
* @param timestamp the explicit event timestamp in nanos since epoch.
|
||||
* @since 0.1.0
|
||||
*/
|
||||
void addEvent(Event event, long timestamp);
|
||||
|
||||
/**
|
||||
* Sets the {@link Status} to the {@code Span}.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -241,7 +241,7 @@ public final class SemanticAttributes {
|
|||
public static final AttributeKey<String> MESSAGING_OPERATION = stringKey("messaging.operation");
|
||||
|
||||
/**
|
||||
* The name of an {@link io.opentelemetry.trace.Event} describing an exception.
|
||||
* The name of an event describing an exception.
|
||||
*
|
||||
* <p>Typically an event with that name should not be manually created. Instead {@link
|
||||
* io.opentelemetry.trace.Span#recordException(Throwable)} should be used.
|
||||
|
|
|
|||
|
|
@ -56,9 +56,6 @@ class DefaultSpanTest {
|
|||
span.addEvent("event", 0);
|
||||
span.addEvent("event", Attributes.of(booleanKey("MyBooleanAttributeKey"), true));
|
||||
span.addEvent("event", Attributes.of(booleanKey("MyBooleanAttributeKey"), true), 0);
|
||||
span.addEvent(new TestEvent());
|
||||
span.addEvent(new TestEvent(), 0);
|
||||
span.addEvent((Event) null);
|
||||
span.setStatus(Status.OK);
|
||||
span.recordException(new IllegalStateException());
|
||||
span.recordException(new IllegalStateException(), Attributes.empty());
|
||||
|
|
@ -72,16 +69,4 @@ class DefaultSpanTest {
|
|||
Span span = DefaultSpan.getInvalid();
|
||||
assertThat(span.toString()).isEqualTo("DefaultSpan");
|
||||
}
|
||||
|
||||
static final class TestEvent implements Event {
|
||||
@Override
|
||||
public String getName() {
|
||||
return "name";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Attributes getAttributes() {
|
||||
return Attributes.empty();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ import static io.opentelemetry.common.AttributesKeys.stringKey;
|
|||
|
||||
import io.opentelemetry.common.AttributeKey;
|
||||
import io.opentelemetry.common.Attributes;
|
||||
import io.opentelemetry.trace.Event;
|
||||
import io.opentelemetry.trace.Span;
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
/**
|
||||
|
|
@ -35,7 +35,7 @@ import javax.annotation.concurrent.Immutable;
|
|||
* @since 0.1.0
|
||||
*/
|
||||
@Immutable
|
||||
public final class MessageEvent implements Event {
|
||||
public final class MessageEvent {
|
||||
|
||||
private static final String EVENT_NAME = "message";
|
||||
private static final AttributeKey<String> TYPE = stringKey("message.type");
|
||||
|
|
@ -63,43 +63,28 @@ public final class MessageEvent implements Event {
|
|||
RECEIVED,
|
||||
}
|
||||
|
||||
private final Attributes attributes;
|
||||
|
||||
/**
|
||||
* Returns a {@code MessageEvent} with the desired values.
|
||||
* Records a {@code MessageEvent} with the desired values to the given Span.
|
||||
*
|
||||
* @param span the span to record the {@code MessageEvent} to.
|
||||
* @param type designates whether this is a send or receive message.
|
||||
* @param messageId serves to uniquely identify each message.
|
||||
* @param uncompressedSize represents the uncompressed size in bytes of this message. If not
|
||||
* available use 0.
|
||||
* @param compressedSize represents the compressed size in bytes of this message. If not available
|
||||
* use 0.
|
||||
* @return a {@code MessageEvent} with the desired values.
|
||||
* @throws NullPointerException if {@code type} is {@code null}.
|
||||
* @since 0.1.0
|
||||
*/
|
||||
public static MessageEvent create(
|
||||
Type type, long messageId, long uncompressedSize, long compressedSize) {
|
||||
public static void record(
|
||||
Span span, Type type, long messageId, long uncompressedSize, long compressedSize) {
|
||||
Attributes.Builder attributeBuilder = Attributes.newBuilder();
|
||||
attributeBuilder.setAttribute(
|
||||
TYPE, type == Type.SENT ? Type.SENT.name() : Type.RECEIVED.name());
|
||||
attributeBuilder.setAttribute(ID, messageId);
|
||||
attributeBuilder.setAttribute(UNCOMPRESSED_SIZE, uncompressedSize);
|
||||
attributeBuilder.setAttribute(COMPRESSED_SIZE, compressedSize);
|
||||
return new MessageEvent(attributeBuilder.build());
|
||||
span.addEvent(EVENT_NAME, attributeBuilder.build());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return EVENT_NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Attributes getAttributes() {
|
||||
return attributes;
|
||||
}
|
||||
|
||||
private MessageEvent(Attributes attributes) {
|
||||
this.attributes = attributes;
|
||||
}
|
||||
private MessageEvent() {}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,7 +28,6 @@ import io.opentelemetry.sdk.common.CompletableResultCode;
|
|||
import io.opentelemetry.sdk.trace.data.SpanData;
|
||||
import io.opentelemetry.sdk.trace.export.SimpleSpanProcessor;
|
||||
import io.opentelemetry.sdk.trace.export.SpanExporter;
|
||||
import io.opentelemetry.trace.Event;
|
||||
import io.opentelemetry.trace.Link;
|
||||
import io.opentelemetry.trace.Span;
|
||||
import io.opentelemetry.trace.Span.Kind;
|
||||
|
|
@ -51,7 +50,6 @@ import org.openjdk.jmh.annotations.Warmup;
|
|||
public class SpanPipelineBenchmark {
|
||||
|
||||
private static final AttributeKey<String> LINK_ATTRIBUTE_KEY = stringKey("linkAttr");
|
||||
private static final AttributeKey<Boolean> FINALIZED_KEY = booleanKey("finalized");
|
||||
private static final AttributeKey<String> OPERATION_KEY = stringKey("operation");
|
||||
private static final AttributeKey<Long> LONG_ATTRIBUTE_KEY = longKey("longAttribute");
|
||||
private static final AttributeKey<String> STRING_ATTRIBUTE_KEY = stringKey("stringAttribute");
|
||||
|
|
@ -92,7 +90,6 @@ public class SpanPipelineBenchmark {
|
|||
span.setStatus(Status.OK);
|
||||
|
||||
span.addEvent("testEvent");
|
||||
span.addEvent(new TestEvent());
|
||||
span.end();
|
||||
}
|
||||
|
||||
|
|
@ -125,16 +122,4 @@ public class SpanPipelineBenchmark {
|
|||
return Attributes.of(LINK_ATTRIBUTE_KEY, "linkValue");
|
||||
}
|
||||
}
|
||||
|
||||
private static class TestEvent implements Event {
|
||||
@Override
|
||||
public String getName() {
|
||||
return "ended";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Attributes getAttributes() {
|
||||
return Attributes.of(FINALIZED_KEY, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,8 +30,8 @@ import io.opentelemetry.internal.StringUtils;
|
|||
import io.opentelemetry.sdk.common.Clock;
|
||||
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
|
||||
import io.opentelemetry.sdk.resources.Resource;
|
||||
import io.opentelemetry.sdk.trace.TimedEvent.RawTimedEventWithEvent;
|
||||
import io.opentelemetry.sdk.trace.config.TraceConfig;
|
||||
import io.opentelemetry.sdk.trace.data.EventImpl;
|
||||
import io.opentelemetry.sdk.trace.data.SpanData;
|
||||
import io.opentelemetry.sdk.trace.data.SpanData.Event;
|
||||
import io.opentelemetry.sdk.trace.data.SpanData.Link;
|
||||
|
|
@ -95,7 +95,7 @@ final class RecordEventsReadableSpan implements ReadWriteSpan {
|
|||
private AttributesMap attributes;
|
||||
// List of recorded events.
|
||||
@GuardedBy("lock")
|
||||
private final EvictingQueue<TimedEvent> events;
|
||||
private final EvictingQueue<EventImpl> events;
|
||||
// Number of events recorded.
|
||||
@GuardedBy("lock")
|
||||
private int totalRecordedEvents = 0;
|
||||
|
|
@ -333,7 +333,7 @@ final class RecordEventsReadableSpan implements ReadWriteSpan {
|
|||
if (name == null) {
|
||||
return;
|
||||
}
|
||||
addTimedEvent(TimedEvent.create(clock.now(), name, Attributes.empty(), 0));
|
||||
addTimedEvent(EventImpl.create(clock.now(), name, Attributes.empty(), 0));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -341,7 +341,7 @@ final class RecordEventsReadableSpan implements ReadWriteSpan {
|
|||
if (name == null) {
|
||||
return;
|
||||
}
|
||||
addTimedEvent(TimedEvent.create(timestamp, name, Attributes.empty(), 0));
|
||||
addTimedEvent(EventImpl.create(timestamp, name, Attributes.empty(), 0));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -351,7 +351,7 @@ final class RecordEventsReadableSpan implements ReadWriteSpan {
|
|||
}
|
||||
int totalAttributeCount = attributes.size();
|
||||
addTimedEvent(
|
||||
TimedEvent.create(
|
||||
EventImpl.create(
|
||||
clock.now(),
|
||||
name,
|
||||
copyAndLimitAttributes(attributes, traceConfig.getMaxNumberOfAttributesPerEvent()),
|
||||
|
|
@ -365,29 +365,13 @@ final class RecordEventsReadableSpan implements ReadWriteSpan {
|
|||
}
|
||||
int totalAttributeCount = attributes.size();
|
||||
addTimedEvent(
|
||||
TimedEvent.create(
|
||||
EventImpl.create(
|
||||
timestamp,
|
||||
name,
|
||||
copyAndLimitAttributes(attributes, traceConfig.getMaxNumberOfAttributesPerEvent()),
|
||||
totalAttributeCount));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addEvent(io.opentelemetry.trace.Event event) {
|
||||
if (event == null) {
|
||||
return;
|
||||
}
|
||||
addTimedEvent(TimedEvent.create(clock.now(), event));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addEvent(io.opentelemetry.trace.Event event, long timestamp) {
|
||||
if (event == null) {
|
||||
return;
|
||||
}
|
||||
addTimedEvent(TimedEvent.create(timestamp, event));
|
||||
}
|
||||
|
||||
static Attributes copyAndLimitAttributes(final Attributes attributes, final int limit) {
|
||||
if (attributes.isEmpty() || attributes.size() <= limit) {
|
||||
return attributes;
|
||||
|
|
@ -398,7 +382,7 @@ final class RecordEventsReadableSpan implements ReadWriteSpan {
|
|||
return result.build();
|
||||
}
|
||||
|
||||
private void addTimedEvent(TimedEvent timedEvent) {
|
||||
private void addTimedEvent(EventImpl timedEvent) {
|
||||
synchronized (lock) {
|
||||
if (hasEnded) {
|
||||
logger.log(Level.FINE, "Calling addEvent() on an ended Span.");
|
||||
|
|
@ -559,22 +543,7 @@ final class RecordEventsReadableSpan implements ReadWriteSpan {
|
|||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
List<Event> results = new ArrayList<>(events.size());
|
||||
for (TimedEvent event : events) {
|
||||
if (event instanceof RawTimedEventWithEvent) {
|
||||
// make sure to copy the data if the event is wrapping another one,
|
||||
// so we don't hold on the caller's memory
|
||||
results.add(
|
||||
TimedEvent.create(
|
||||
event.getEpochNanos(),
|
||||
event.getName(),
|
||||
event.getAttributes(),
|
||||
event.getTotalAttributeCount()));
|
||||
} else {
|
||||
results.add(event);
|
||||
}
|
||||
}
|
||||
return Collections.unmodifiableList(results);
|
||||
return Collections.unmodifiableList(new ArrayList<>(events));
|
||||
}
|
||||
|
||||
@GuardedBy("lock")
|
||||
|
|
|
|||
|
|
@ -1,80 +0,0 @@
|
|||
/*
|
||||
* 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.sdk.trace;
|
||||
|
||||
import com.google.auto.value.AutoValue;
|
||||
import io.opentelemetry.common.Attributes;
|
||||
import io.opentelemetry.trace.Event;
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
/** Timed event. */
|
||||
@Immutable
|
||||
abstract class TimedEvent implements io.opentelemetry.sdk.trace.data.SpanData.Event {
|
||||
|
||||
private static final int DEFAULT_TOTAL_ATTRIBUTE_COUNT = 0;
|
||||
|
||||
TimedEvent() {}
|
||||
|
||||
/**
|
||||
* Creates an {@link TimedEvent} with the given time, name and attributes.
|
||||
*
|
||||
* @param epochNanos epoch timestamp in nanos.
|
||||
* @param name the name of this {@code TimedEvent}.
|
||||
* @param attributes the attributes of this {@code TimedEvent}.
|
||||
* @return an {@code TimedEvent}.
|
||||
*/
|
||||
static TimedEvent create(
|
||||
long epochNanos, String name, Attributes attributes, int totalAttributeCount) {
|
||||
return new AutoValue_TimedEvent_RawTimedEvent(
|
||||
name, attributes, epochNanos, totalAttributeCount);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an {@link TimedEvent} with the given time and event.
|
||||
*
|
||||
* @param epochNanos epoch timestamp in nanos.
|
||||
* @param event the event.
|
||||
* @return an {@code TimedEvent}.
|
||||
*/
|
||||
static TimedEvent create(long epochNanos, Event event) {
|
||||
return new AutoValue_TimedEvent_RawTimedEventWithEvent(
|
||||
epochNanos, event, DEFAULT_TOTAL_ATTRIBUTE_COUNT);
|
||||
}
|
||||
|
||||
@AutoValue
|
||||
@Immutable
|
||||
abstract static class RawTimedEventWithEvent extends TimedEvent {
|
||||
abstract Event getEvent();
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return getEvent().getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Attributes getAttributes() {
|
||||
return getEvent().getAttributes();
|
||||
}
|
||||
|
||||
@Override
|
||||
public abstract int getTotalAttributeCount();
|
||||
}
|
||||
|
||||
@AutoValue
|
||||
@Immutable
|
||||
abstract static class RawTimedEvent extends TimedEvent {}
|
||||
}
|
||||
|
|
@ -23,7 +23,7 @@ import io.opentelemetry.internal.Utils;
|
|||
import io.opentelemetry.sdk.common.export.ConfigBuilder;
|
||||
import io.opentelemetry.sdk.trace.Sampler;
|
||||
import io.opentelemetry.sdk.trace.Samplers;
|
||||
import io.opentelemetry.trace.Event;
|
||||
import io.opentelemetry.sdk.trace.data.SpanData.Event;
|
||||
import io.opentelemetry.trace.Link;
|
||||
import io.opentelemetry.trace.Span;
|
||||
import java.util.Map;
|
||||
|
|
|
|||
|
|
@ -44,15 +44,15 @@
|
|||
* <li>{@code otel.config.sampler.probability}: to set the global default sampler which is used
|
||||
* when constructing a new {@code Span}.
|
||||
* <li>{@code otel.config.max.attrs}: to set the global default max number of attributes per
|
||||
* {@link io.opentelemetry.trace.Span}.
|
||||
* <li>{@code otel.config.max.events}: to set the global default max number of {@link
|
||||
* io.opentelemetry.trace.Event}s per {@link io.opentelemetry.trace.Span}.
|
||||
* <li>{@code otel.config.max.links}: to set the global default max number of {@link
|
||||
* io.opentelemetry.trace.Link} entries per {@link io.opentelemetry.trace.Span}.
|
||||
* {@code Span}.
|
||||
* <li>{@code otel.config.max.events}: to set the global default max number of events per {@code
|
||||
* Span}.
|
||||
* <li>{@code otel.config.max.links}: to set the global default max number of links per {@code
|
||||
* Span}.
|
||||
* <li>{@code otel.config.max.event.attrs}: to set the global default max number of attributes per
|
||||
* {@link io.opentelemetry.trace.Event}.
|
||||
* event.
|
||||
* <li>{@code otel.config.max.link.attrs}: to set the global default max number of attributes per
|
||||
* {@link io.opentelemetry.trace.Link}.
|
||||
* link.
|
||||
* </ul>
|
||||
*
|
||||
* <p>For environment variable, {@link io.opentelemetry.sdk.trace.config.TraceConfig} will look for
|
||||
|
|
@ -62,15 +62,15 @@
|
|||
* <li>{@code OTEL_CONFIG_SAMPLER_PROBABILITY}: to set the global default sampler which is used
|
||||
* when constructing a new {@code Span}.
|
||||
* <li>{@code OTEL_CONFIG_MAX_ATTRS}: to set the global default max number of attributes per
|
||||
* {@link io.opentelemetry.trace.Span}.
|
||||
* <li>{@code OTEL_CONFIG_MAX_EVENTS}: to set the global default max number of {@link
|
||||
* io.opentelemetry.trace.Event}s per {@link io.opentelemetry.trace.Span}.
|
||||
* <li>{@code OTEL_CONFIG_MAX_LINKS}: to set the global default max number of {@link
|
||||
* io.opentelemetry.trace.Link} entries per {@link io.opentelemetry.trace.Span}.
|
||||
* {@code Span}.
|
||||
* <li>{@code OTEL_CONFIG_MAX_EVENTS}: to set the global default max number of events per {@code
|
||||
* Span}.
|
||||
* <li>{@code OTEL_CONFIG_MAX_LINKS}: to set the global default max number of links entries per
|
||||
* {@code Span}.
|
||||
* <li>{@code OTEL_CONFIG_MAX_EVENT_ATTRS}: to set the global default max number of attributes per
|
||||
* {@link io.opentelemetry.trace.Event}.
|
||||
* event.
|
||||
* <li>{@code OTEL_CONFIG_MAX_LINK_ATTRS}: to set the global default max number of attributes per
|
||||
* {@link io.opentelemetry.trace.Link}.
|
||||
* link.
|
||||
* </ul>
|
||||
*/
|
||||
package io.opentelemetry.sdk.trace.config;
|
||||
|
|
|
|||
|
|
@ -20,10 +20,7 @@ import com.google.auto.value.AutoValue;
|
|||
import io.opentelemetry.common.Attributes;
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
/**
|
||||
* An immutable timed event representation. Enhances the core {@link io.opentelemetry.trace.Event}
|
||||
* by adding the time at which the event occurred.
|
||||
*/
|
||||
/** An immutable implementation of the {@link SpanData.Event}. */
|
||||
@Immutable
|
||||
@AutoValue
|
||||
public abstract class EventImpl implements SpanData.Event {
|
||||
|
|
|
|||
|
|
@ -237,7 +237,23 @@ public interface SpanData {
|
|||
Link() {}
|
||||
}
|
||||
|
||||
interface Event extends io.opentelemetry.trace.Event {
|
||||
interface Event {
|
||||
/**
|
||||
* Return the name of the {@code Event}.
|
||||
*
|
||||
* @return the name of the {@code Event}.
|
||||
* @since 0.1.0
|
||||
*/
|
||||
String getName();
|
||||
|
||||
/**
|
||||
* Return the attributes of the {@code Event}.
|
||||
*
|
||||
* @return the attributes of the {@code Event}.
|
||||
* @since 0.1.0
|
||||
*/
|
||||
Attributes getAttributes();
|
||||
|
||||
/**
|
||||
* Returns the epoch time in nanos of this event.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -173,7 +173,7 @@ class RecordEventsReadableSpanTest {
|
|||
spanDoWork(span, null);
|
||||
SpanData spanData = span.toSpanData();
|
||||
Event event =
|
||||
TimedEvent.create(START_EPOCH_NANOS + NANOS_PER_SECOND, "event2", Attributes.empty(), 0);
|
||||
EventImpl.create(START_EPOCH_NANOS + NANOS_PER_SECOND, "event2", Attributes.empty(), 0);
|
||||
verifySpanData(
|
||||
spanData,
|
||||
expectedAttributes,
|
||||
|
|
@ -202,7 +202,7 @@ class RecordEventsReadableSpanTest {
|
|||
Mockito.verify(spanProcessor, Mockito.times(1)).onEnd(span);
|
||||
SpanData spanData = span.toSpanData();
|
||||
Event event =
|
||||
TimedEvent.create(START_EPOCH_NANOS + NANOS_PER_SECOND, "event2", Attributes.empty(), 0);
|
||||
EventImpl.create(START_EPOCH_NANOS + NANOS_PER_SECOND, "event2", Attributes.empty(), 0);
|
||||
verifySpanData(
|
||||
spanData,
|
||||
expectedAttributes,
|
||||
|
|
@ -515,33 +515,14 @@ class RecordEventsReadableSpanTest {
|
|||
@Test
|
||||
void addEvent() {
|
||||
RecordEventsReadableSpan span = createTestRootSpan();
|
||||
io.opentelemetry.trace.Event customEvent =
|
||||
new io.opentelemetry.trace.Event() {
|
||||
@Override
|
||||
public String getName() {
|
||||
return "event3";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Attributes getAttributes() {
|
||||
return Attributes.empty();
|
||||
}
|
||||
};
|
||||
try {
|
||||
span.addEvent("event1");
|
||||
span.addEvent("event2", Attributes.of(stringKey("e1key"), "e1Value"));
|
||||
span.addEvent(customEvent);
|
||||
} finally {
|
||||
span.end();
|
||||
}
|
||||
List<Event> events = span.toSpanData().getEvents();
|
||||
assertThat(events.size()).isEqualTo(3);
|
||||
for (Event event : events) {
|
||||
// make sure that we aren't holding on to the memory from the custom event, in case it
|
||||
// references
|
||||
// some heavyweight thing.
|
||||
assertThat(event).isNotInstanceOf(TimedEvent.RawTimedEventWithEvent.class);
|
||||
}
|
||||
assertThat(events.size()).isEqualTo(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -622,7 +603,7 @@ class RecordEventsReadableSpanTest {
|
|||
assertThat(spanData.getEvents().size()).isEqualTo(maxNumberOfEvents);
|
||||
for (int i = 0; i < maxNumberOfEvents; i++) {
|
||||
Event expectedEvent =
|
||||
TimedEvent.create(
|
||||
EventImpl.create(
|
||||
START_EPOCH_NANOS + (maxNumberOfEvents + i) * NANOS_PER_SECOND,
|
||||
"event2",
|
||||
Attributes.empty(),
|
||||
|
|
@ -637,7 +618,7 @@ class RecordEventsReadableSpanTest {
|
|||
assertThat(spanData.getEvents().size()).isEqualTo(maxNumberOfEvents);
|
||||
for (int i = 0; i < maxNumberOfEvents; i++) {
|
||||
Event expectedEvent =
|
||||
TimedEvent.create(
|
||||
EventImpl.create(
|
||||
START_EPOCH_NANOS + (maxNumberOfEvents + i) * NANOS_PER_SECOND,
|
||||
"event2",
|
||||
Attributes.empty(),
|
||||
|
|
@ -746,10 +727,8 @@ class RecordEventsReadableSpanTest {
|
|||
span.setAttribute(null, 0L);
|
||||
span.setStatus(null);
|
||||
span.updateName(null);
|
||||
span.addEvent((Event) null);
|
||||
span.addEvent((String) null);
|
||||
span.addEvent((Event) null, 0);
|
||||
span.addEvent((String) null, 0);
|
||||
span.addEvent(null);
|
||||
span.addEvent(null, 0);
|
||||
span.addEvent(null, null);
|
||||
span.addEvent(null, null, 0);
|
||||
span.recordException(null);
|
||||
|
|
@ -920,9 +899,9 @@ class RecordEventsReadableSpanTest {
|
|||
|
||||
List<Event> events =
|
||||
Arrays.asList(
|
||||
TimedEvent.create(
|
||||
EventImpl.create(
|
||||
firstEventEpochNanos, "event1", event1Attributes, event1Attributes.size()),
|
||||
TimedEvent.create(
|
||||
EventImpl.create(
|
||||
secondEventTimeNanos, "event2", event2Attributes, event2Attributes.size()));
|
||||
|
||||
SpanData result = readableSpan.toSpanData();
|
||||
|
|
|
|||
|
|
@ -1,62 +0,0 @@
|
|||
/*
|
||||
* 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.sdk.trace;
|
||||
|
||||
import static io.opentelemetry.common.AttributesKeys.stringKey;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import io.opentelemetry.common.Attributes;
|
||||
import io.opentelemetry.trace.Event;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/** Unit tests for {@link TimedEvent}. */
|
||||
class TimedEventTest {
|
||||
|
||||
private static final String NAME = "event";
|
||||
private static final String NAME_2 = "event2";
|
||||
private static final Attributes ATTRIBUTES = Attributes.of(stringKey("attribute"), "value");
|
||||
private static final Attributes ATTRIBUTES_2 = Attributes.of(stringKey("attribute2"), "value2");
|
||||
private static final Event EVENT =
|
||||
new Event() {
|
||||
@Override
|
||||
public String getName() {
|
||||
return NAME_2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Attributes getAttributes() {
|
||||
return ATTRIBUTES_2;
|
||||
}
|
||||
};
|
||||
|
||||
@Test
|
||||
void rawTimedEventWithNameAndAttributesAndTotalAttributeCount() {
|
||||
TimedEvent event = TimedEvent.create(1234567890L, NAME, ATTRIBUTES, ATTRIBUTES.size() + 2);
|
||||
assertThat(event.getEpochNanos()).isEqualTo(1234567890L);
|
||||
assertThat(event.getName()).isEqualTo(NAME);
|
||||
assertThat(event.getAttributes()).isEqualTo(ATTRIBUTES);
|
||||
assertThat(event.getTotalAttributeCount()).isEqualTo(ATTRIBUTES.size() + 2);
|
||||
}
|
||||
|
||||
@Test
|
||||
void rawTimedEventWithEvent() {
|
||||
TimedEvent event = TimedEvent.create(9876501234L, EVENT);
|
||||
assertThat(event.getEpochNanos()).isEqualTo(9876501234L);
|
||||
assertThat(event.getName()).isEqualTo(NAME_2);
|
||||
assertThat(event.getAttributes()).isEqualTo(ATTRIBUTES_2);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue