General Attributes Typed Spans
ADD
agent-bootstrap/src/main/java/io/opentelemetry/auto/typedspan/IdentitySemanticConvention.java
+/*
+ * Copyright The 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.auto.typedspan;
+
+import io.opentelemetry.trace.Span;
+
+public interface IdentitySemanticConvention {
+ void end();
+
+ Span getSpan();
+
+ /**
+ * Sets a value for enduser.id
+ *
+ * @param enduserId Username or client_id extracted from the access token or Authorization header
+ * in the inbound request from outside the system.
+ */
+ IdentitySemanticConvention setEnduserId(String enduserId);
+
+ /**
+ * Sets a value for enduser.role
+ *
+ * @param enduserRole Actual/assumed role the client is making the request under extracted from
+ * token or application security context.
+ */
+ IdentitySemanticConvention setEnduserRole(String enduserRole);
+
+ /**
+ * Sets a value for enduser.scope
+ *
+ * @param enduserScope Scopes or granted authorities the client currently possesses extracted from
+ * token or application security context. The value would come from the scope associated with
+ * an OAuth 2.0 Access Token or an attribute value in a SAML 2.0 Assertion.
+ */
+ IdentitySemanticConvention setEnduserScope(String enduserScope);
+}

ADD
agent-bootstrap/src/main/java/io/opentelemetry/auto/typedspan/IdentitySpan.java
+/*
+ * Copyright The 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.auto.typedspan;
+
+import io.opentelemetry.trace.Span;
+import io.opentelemetry.trace.SpanContext;
+import io.opentelemetry.trace.Tracer;
+
+public class IdentitySpan extends DelegatingSpan implements IdentitySemanticConvention {
+
+ protected IdentitySpan(Span span) {
+ super(span);
+ }
+
+ /**
+ * Entry point to generate a {@link IdentitySpan}.
+ *
+ * @param tracer Tracer to use
+ * @param spanName Name for the {@link Span}
+ * @return a {@link IdentitySpan} object.
+ */
+ public static IdentitySpanBuilder createIdentitySpan(Tracer tracer, String spanName) {
+ return new IdentitySpanBuilder(tracer, spanName);
+ }
+
+ /** @return the Span used internally */
+ @Override
+ public Span getSpan() {
+ return this.delegate;
+ }
+
+ /** Terminates the Span. Here there is the checking for required attributes. */
+ @Override
+ public void end() {
+ delegate.end();
+ }
+
+ /**
+ * Sets enduser.id.
+ *
+ * @param enduserId Username or client_id extracted from the access token or Authorization header
+ * in the inbound request from outside the system.
+ */
+ @Override
+ public IdentitySemanticConvention setEnduserId(String enduserId) {
+ delegate.setAttribute("enduser.id", enduserId);
+ return this;
+ }
+
+ /**
+ * Sets enduser.role.
+ *
+ * @param enduserRole Actual/assumed role the client is making the request under extracted from
+ * token or application security context.
+ */
+ @Override
+ public IdentitySemanticConvention setEnduserRole(String enduserRole) {
+ delegate.setAttribute("enduser.role", enduserRole);
+ return this;
+ }
+
+ /**
+ * Sets enduser.scope.
+ *
+ * @param enduserScope Scopes or granted authorities the client currently possesses extracted from
+ * token or application security context. The value would come from the scope associated with
+ * an OAuth 2.0 Access Token or an attribute value in a SAML 2.0 Assertion.
+ */
+ @Override
+ public IdentitySemanticConvention setEnduserScope(String enduserScope) {
+ delegate.setAttribute("enduser.scope", enduserScope);
+ return this;
+ }
+
+ /** Builder class for {@link IdentitySpan}. */
+ public static class IdentitySpanBuilder {
+ // Protected because maybe we want to extend manually these classes
+ protected Span.Builder internalBuilder;
+
+ protected IdentitySpanBuilder(Tracer tracer, String spanName) {
+ internalBuilder = tracer.spanBuilder(spanName);
+ }
+
+ public IdentitySpanBuilder(Span.Builder spanBuilder) {
+ this.internalBuilder = spanBuilder;
+ }
+
+ public Span.Builder getSpanBuilder() {
+ return this.internalBuilder;
+ }
+
+ /** sets the {@link Span} parent. */
+ public IdentitySpanBuilder setParent(Span parent) {
+ this.internalBuilder.setParent(parent);
+ return this;
+ }
+
+ /** sets the {@link Span} parent. */
+ public IdentitySpanBuilder setParent(SpanContext remoteParent) {
+ this.internalBuilder.setParent(remoteParent);
+ return this;
+ }
+
+ /** this method sets the type of the {@link Span} is only available in the builder. */
+ public IdentitySpanBuilder setKind(Span.Kind kind) {
+ internalBuilder.setSpanKind(kind);
+ return this;
+ }
+
+ /** starts the span */
+ public IdentitySpan start() {
+ // check for sampling relevant field here, but there are none.
+ return new IdentitySpan(this.internalBuilder.startSpan());
+ }
+
+ /**
+ * Sets enduser.id.
+ *
+ * @param enduserId Username or client_id extracted from the access token or Authorization
+ * header in the inbound request from outside the system.
+ */
+ public IdentitySpanBuilder setEnduserId(String enduserId) {
+ internalBuilder.setAttribute("enduser.id", enduserId);
+ return this;
+ }
+
+ /**
+ * Sets enduser.role.
+ *
+ * @param enduserRole Actual/assumed role the client is making the request under extracted from
+ * token or application security context.
+ */
+ public IdentitySpanBuilder setEnduserRole(String enduserRole) {
+ internalBuilder.setAttribute("enduser.role", enduserRole);
+ return this;
+ }
+
+ /**
+ * Sets enduser.scope.
+ *
+ * @param enduserScope Scopes or granted authorities the client currently possesses extracted
+ * from token or application security context. The value would come from the scope
+ * associated with an OAuth 2.0 Access Token or an attribute value in a SAML 2.0 Assertion.
+ */
+ public IdentitySpanBuilder setEnduserScope(String enduserScope) {
+ internalBuilder.setAttribute("enduser.scope", enduserScope);
+ return this;
+ }
+ }
+}

ADD
agent-bootstrap/src/main/java/io/opentelemetry/auto/typedspan/NetworkSemanticConvention.java
+/*
+ * Copyright The 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.auto.typedspan;
+
+import io.opentelemetry.trace.Span;
+
+public interface NetworkSemanticConvention {
+ void end();
+
+ Span getSpan();
+
+ /**
+ * Sets a value for net.transport
+ *
+ * @param netTransport Transport protocol used. See note below.
+ */
+ NetworkSemanticConvention setNetTransport(String netTransport);
+
+ /**
+ * Sets a value for net.peer.ip
+ *
+ * @param netPeerIp Remote address of the peer (dotted decimal for IPv4 or
+ * [RFC5952](https://tools.ietf.org/html/rfc5952) for IPv6).
+ */
+ NetworkSemanticConvention setNetPeerIp(String netPeerIp);
+
+ /**
+ * Sets a value for net.peer.port
+ *
+ * @param netPeerPort Remote port number.
+ */
+ NetworkSemanticConvention setNetPeerPort(long netPeerPort);
+
+ /**
+ * Sets a value for net.peer.name
+ *
+ * @param netPeerName Remote hostname or similar, see note below.
+ */
+ NetworkSemanticConvention setNetPeerName(String netPeerName);
+
+ /**
+ * Sets a value for net.host.ip
+ *
+ * @param netHostIp Like `net.peer.ip` but for the host IP. Useful in case of a multi-IP host.
+ */
+ NetworkSemanticConvention setNetHostIp(String netHostIp);
+
+ /**
+ * Sets a value for net.host.port
+ *
+ * @param netHostPort Like `net.peer.port` but for the host port.
+ */
+ NetworkSemanticConvention setNetHostPort(long netHostPort);
+
+ /**
+ * Sets a value for net.host.name
+ *
+ * @param netHostName Local hostname or similar, see note below.
+ */
+ NetworkSemanticConvention setNetHostName(String netHostName);
+}

ADD
agent-bootstrap/src/main/java/io/opentelemetry/auto/typedspan/NetworkSpan.java
+/*
+ * Copyright The 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.auto.typedspan;
+
+import io.opentelemetry.trace.Span;
+import io.opentelemetry.trace.SpanContext;
+import io.opentelemetry.trace.Tracer;
+
+public class NetworkSpan extends DelegatingSpan implements NetworkSemanticConvention {
+
+ protected NetworkSpan(Span span) {
+ super(span);
+ }
+
+ /**
+ * Entry point to generate a {@link NetworkSpan}.
+ *
+ * @param tracer Tracer to use
+ * @param spanName Name for the {@link Span}
+ * @return a {@link NetworkSpan} object.
+ */
+ public static NetworkSpanBuilder createNetworkSpan(Tracer tracer, String spanName) {
+ return new NetworkSpanBuilder(tracer, spanName);
+ }
+
+ /** @return the Span used internally */
+ @Override
+ public Span getSpan() {
+ return this.delegate;
+ }
+
+ /** Terminates the Span. Here there is the checking for required attributes. */
+ @Override
+ public void end() {
+ delegate.end();
+ }
+
+ /**
+ * Sets net.transport.
+ *
+ * @param netTransport Transport protocol used. See note below.
+ */
+ @Override
+ public NetworkSemanticConvention setNetTransport(String netTransport) {
+ delegate.setAttribute("net.transport", netTransport);
+ return this;
+ }
+
+ /**
+ * Sets net.peer.ip.
+ *
+ * @param netPeerIp Remote address of the peer (dotted decimal for IPv4 or
+ * [RFC5952](https://tools.ietf.org/html/rfc5952) for IPv6).
+ */
+ @Override
+ public NetworkSemanticConvention setNetPeerIp(String netPeerIp) {
+ delegate.setAttribute("net.peer.ip", netPeerIp);
+ return this;
+ }
+
+ /**
+ * Sets net.peer.port.
+ *
+ * @param netPeerPort Remote port number.
+ */
+ @Override
+ public NetworkSemanticConvention setNetPeerPort(long netPeerPort) {
+ delegate.setAttribute("net.peer.port", netPeerPort);
+ return this;
+ }
+
+ /**
+ * Sets net.peer.name.
+ *
+ * @param netPeerName Remote hostname or similar, see note below.
+ */
+ @Override
+ public NetworkSemanticConvention setNetPeerName(String netPeerName) {
+ delegate.setAttribute("net.peer.name", netPeerName);
+ return this;
+ }
+
+ /**
+ * Sets net.host.ip.
+ *
+ * @param netHostIp Like `net.peer.ip` but for the host IP. Useful in case of a multi-IP host.
+ */
+ @Override
+ public NetworkSemanticConvention setNetHostIp(String netHostIp) {
+ delegate.setAttribute("net.host.ip", netHostIp);
+ return this;
+ }
+
+ /**
+ * Sets net.host.port.
+ *
+ * @param netHostPort Like `net.peer.port` but for the host port.
+ */
+ @Override
+ public NetworkSemanticConvention setNetHostPort(long netHostPort) {
+ delegate.setAttribute("net.host.port", netHostPort);
+ return this;
+ }
+
+ /**
+ * Sets net.host.name.
+ *
+ * @param netHostName Local hostname or similar, see note below.
+ */
+ @Override
+ public NetworkSemanticConvention setNetHostName(String netHostName) {
+ delegate.setAttribute("net.host.name", netHostName);
+ return this;
+ }
+
+ /** Builder class for {@link NetworkSpan}. */
+ public static class NetworkSpanBuilder {
+ // Protected because maybe we want to extend manually these classes
+ protected Span.Builder internalBuilder;
+
+ protected NetworkSpanBuilder(Tracer tracer, String spanName) {
+ internalBuilder = tracer.spanBuilder(spanName);
+ }
+
+ public NetworkSpanBuilder(Span.Builder spanBuilder) {
+ this.internalBuilder = spanBuilder;
+ }
+
+ public Span.Builder getSpanBuilder() {
+ return this.internalBuilder;
+ }
+
+ /** sets the {@link Span} parent. */
+ public NetworkSpanBuilder setParent(Span parent) {
+ this.internalBuilder.setParent(parent);
+ return this;
+ }
+
+ /** sets the {@link Span} parent. */
+ public NetworkSpanBuilder setParent(SpanContext remoteParent) {
+ this.internalBuilder.setParent(remoteParent);
+ return this;
+ }
+
+ /** this method sets the type of the {@link Span} is only available in the builder. */
+ public NetworkSpanBuilder setKind(Span.Kind kind) {
+ internalBuilder.setSpanKind(kind);
+ return this;
+ }
+
+ /** starts the span */
+ public NetworkSpan start() {
+ // check for sampling relevant field here, but there are none.
+ return new NetworkSpan(this.internalBuilder.startSpan());
+ }
+
+ /**
+ * Sets net.transport.
+ *
+ * @param netTransport Transport protocol used. See note below.
+ */
+ public NetworkSpanBuilder setNetTransport(String netTransport) {
+ internalBuilder.setAttribute("net.transport", netTransport);
+ return this;
+ }
+
+ /**
+ * Sets net.peer.ip.
+ *
+ * @param netPeerIp Remote address of the peer (dotted decimal for IPv4 or
+ * [RFC5952](https://tools.ietf.org/html/rfc5952) for IPv6).
+ */
+ public NetworkSpanBuilder setNetPeerIp(String netPeerIp) {
+ internalBuilder.setAttribute("net.peer.ip", netPeerIp);
+ return this;
+ }
+
+ /**
+ * Sets net.peer.port.
+ *
+ * @param netPeerPort Remote port number.
+ */
+ public NetworkSpanBuilder setNetPeerPort(long netPeerPort) {
+ internalBuilder.setAttribute("net.peer.port", netPeerPort);
+ return this;
+ }
+
+ /**
+ * Sets net.peer.name.
+ *
+ * @param netPeerName Remote hostname or similar, see note below.
+ */
+ public NetworkSpanBuilder setNetPeerName(String netPeerName) {
+ internalBuilder.setAttribute("net.peer.name", netPeerName);
+ return this;
+ }
+
+ /**
+ * Sets net.host.ip.
+ *
+ * @param netHostIp Like `net.peer.ip` but for the host IP. Useful in case of a multi-IP host.
+ */
+ public NetworkSpanBuilder setNetHostIp(String netHostIp) {
+ internalBuilder.setAttribute("net.host.ip", netHostIp);
+ return this;
+ }
+
+ /**
+ * Sets net.host.port.
+ *
+ * @param netHostPort Like `net.peer.port` but for the host port.
+ */
+ public NetworkSpanBuilder setNetHostPort(long netHostPort) {
+ internalBuilder.setAttribute("net.host.port", netHostPort);
+ return this;
+ }
+
+ /**
+ * Sets net.host.name.
+ *
+ * @param netHostName Local hostname or similar, see note below.
+ */
+ public NetworkSpanBuilder setNetHostName(String netHostName) {
+ internalBuilder.setAttribute("net.host.name", netHostName);
+ return this;
+ }
+ }
+}

General Attributes Typed Spans (#854)