Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add incubator module with utilities for mutating SpanData. #1625

Merged
merged 3 commits into from
Sep 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions sdk_extensions/tracing_incubator/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
plugins {
id "java"
id "maven-publish"

id "ru.vyarus.animalsniffer"
}

// SDK modules that are still being developed.

description = 'OpenTelemetry SDK Tracing Incubator'
ext.moduleName = "io.opentelemetry.sdk.extension.trace.incubator"

dependencies {
api project(':opentelemetry-api'),
project(':opentelemetry-sdk')


annotationProcessor libraries.auto_value
testImplementation project(':opentelemetry-testing-internal')

signature "org.codehaus.mojo.signature:java17:1.0@signature"
signature "net.sf.androidscents.signature:android-api-level-24:7.0_r2@signature"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,307 @@
/*
* Copyright 2020, 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.extensions.incubator.trace.data;

import static java.util.Objects.requireNonNull;

import io.opentelemetry.common.ReadableAttributes;
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
import io.opentelemetry.sdk.resources.Resource;
import io.opentelemetry.sdk.trace.data.SpanData;
import io.opentelemetry.trace.Span.Kind;
import io.opentelemetry.trace.Status;
import io.opentelemetry.trace.TraceState;
import java.util.List;

/**
* A {@link SpanData} which delegates all methods to another {@link SpanData}. Extend this class to
* modify the {@link SpanData} that will be exported, for example by creating a delegating {@link
* io.opentelemetry.sdk.trace.export.SpanExporter} which wraps {@link SpanData} with a custom
* implementation.
*
* <pre>{@code
* SpanDataWithClientType extends DelegatingSpanData {
*
* private final ReadableAttributes attributes;
*
* SpanDataWithClientType(SpanData delegate) {
* super(delegate);
* String clientType = ClientConfig.parseUserAgent(
* delegate.getAttributes().get(SemanticAttributes.HTTP_USER_AGENT).getStringValue());
* Attributes.Builder newAttributes = Attributes.newBuilder(delegate.getAttributes());
* newAttributes.setAttribute("client_type", clientType);
* attributes = newAttributes.build();
* }
*
* {@literal @}Override
* public ReadableAttributes getAttributes() {
* return attributes;
* }
* }
*
* }</pre>
*/
public abstract class DelegatingSpanData implements SpanData {

private final SpanData delegate;

protected DelegatingSpanData(SpanData delegate) {
this.delegate = requireNonNull(delegate, "delegate");
}

@Override
public String getTraceId() {
return delegate.getTraceId();
}

@Override
public String getSpanId() {
return delegate.getSpanId();
}

@Override
public boolean isSampled() {
return delegate.isSampled();
}

@Override
public TraceState getTraceState() {
return delegate.getTraceState();
}

@Override
public String getParentSpanId() {
return delegate.getParentSpanId();
}

@Override
public Resource getResource() {
return delegate.getResource();
}

@Override
public InstrumentationLibraryInfo getInstrumentationLibraryInfo() {
return delegate.getInstrumentationLibraryInfo();
}

@Override
public String getName() {
return delegate.getName();
}

@Override
public Kind getKind() {
return delegate.getKind();
}

@Override
public long getStartEpochNanos() {
return delegate.getStartEpochNanos();
}

@Override
public ReadableAttributes getAttributes() {
return delegate.getAttributes();
}

@Override
public List<Event> getEvents() {
return delegate.getEvents();
}

@Override
public List<Link> getLinks() {
return delegate.getLinks();
}

@Override
public Status getStatus() {
return delegate.getStatus();
}

@Override
public long getEndEpochNanos() {
return delegate.getEndEpochNanos();
}

@Override
public boolean getHasRemoteParent() {
return delegate.getHasRemoteParent();
}

@Override
public boolean getHasEnded() {
return delegate.getHasEnded();
}

@Override
public int getTotalRecordedEvents() {
return delegate.getTotalRecordedEvents();
}

@Override
public int getTotalRecordedLinks() {
return delegate.getTotalRecordedLinks();
}

@Override
public int getTotalAttributeCount() {
return delegate.getTotalAttributeCount();
}

@Override
public final boolean equals(Object o) {
if (o == this) {
return true;
}
if (o instanceof SpanData) {
SpanData that = (SpanData) o;
return getTraceId().equals(that.getTraceId())
&& getSpanId().equals(that.getSpanId())
&& isSampled() == that.isSampled()
&& getTraceState().equals(that.getTraceState())
&& getParentSpanId().equals(that.getParentSpanId())
&& getResource().equals(that.getResource())
&& getInstrumentationLibraryInfo().equals(that.getInstrumentationLibraryInfo())
&& getName().equals(that.getName())
&& getKind().equals(that.getKind())
&& getStartEpochNanos() == that.getStartEpochNanos()
&& getAttributes().equals(that.getAttributes())
&& getEvents().equals(that.getEvents())
&& getLinks().equals(that.getLinks())
&& getStatus().equals(that.getStatus())
&& getEndEpochNanos() == that.getEndEpochNanos()
&& getHasRemoteParent() == that.getHasRemoteParent()
&& getHasEnded() == that.getHasEnded()
&& getTotalRecordedEvents() == that.getTotalRecordedEvents()
&& getTotalRecordedLinks() == that.getTotalRecordedLinks()
&& getTotalAttributeCount() == that.getTotalAttributeCount();
}
return false;
}

@Override
public int hashCode() {
int code = 1;
code *= 1000003;
code ^= getTraceId().hashCode();
code *= 1000003;
code ^= getSpanId().hashCode();
code *= 1000003;
code ^= getTraceId().hashCode();
code *= 1000003;
code ^= getTraceState().hashCode();
code *= 1000003;
code ^= getParentSpanId().hashCode();
code *= 1000003;
code ^= getResource().hashCode();
code *= 1000003;
code ^= getInstrumentationLibraryInfo().hashCode();
code *= 1000003;
code ^= getName().hashCode();
code *= 1000003;
code ^= getKind().hashCode();
code *= 1000003;
code ^= (int) ((getStartEpochNanos() >>> 32) ^ getStartEpochNanos());
code *= 1000003;
code ^= getAttributes().hashCode();
code *= 1000003;
code ^= getEvents().hashCode();
code *= 1000003;
code ^= getLinks().hashCode();
code *= 1000003;
code ^= getStatus().hashCode();
code *= 1000003;
code ^= (int) ((getEndEpochNanos() >>> 32) ^ getEndEpochNanos());
code *= 1000003;
code ^= getHasRemoteParent() ? 1231 : 1237;
code *= 1000003;
code ^= getHasEnded() ? 1231 : 1237;
code *= 1000003;
code ^= getTotalRecordedEvents();
code *= 1000003;
code ^= getTotalRecordedLinks();
code *= 1000003;
code ^= getTotalAttributeCount();
return code;
}

@Override
public String toString() {
return "SpanDataImpl{"
+ "traceId="
+ getTraceId()
+ ", "
+ "spanId="
+ getSpanId()
+ ", "
+ "isSampled="
+ isSampled()
+ ", "
+ "traceState="
+ getTraceState()
+ ", "
+ "parentSpanId="
+ getParentSpanId()
+ ", "
+ "resource="
+ getResource()
+ ", "
+ "instrumentationLibraryInfo="
+ getInstrumentationLibraryInfo()
+ ", "
+ "name="
+ getName()
+ ", "
+ "kind="
+ getKind()
+ ", "
+ "startEpochNanos="
+ getStartEpochNanos()
+ ", "
+ "attributes="
+ getAttributes()
+ ", "
+ "events="
+ getEvents()
+ ", "
+ "links="
+ getLinks()
+ ", "
+ "status="
+ getStatus()
+ ", "
+ "endEpochNanos="
+ getEndEpochNanos()
+ ", "
+ "hasRemoteParent="
+ getHasRemoteParent()
+ ", "
+ "hasEnded="
+ getHasEnded()
+ ", "
+ "totalRecordedEvents="
+ getTotalRecordedEvents()
+ ", "
+ "totalRecordedLinks="
+ getTotalRecordedLinks()
+ ", "
+ "totalAttributeCount="
+ getTotalAttributeCount()
+ "}";
}
}
Loading