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

Deprecate AttributesExtractor#set() method #5749

Merged
merged 2 commits into from
Apr 6, 2022
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
2 changes: 1 addition & 1 deletion docs/logger-mdc-instrumentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ event's MDC copy:
(same as `Span.current().getSpanContext().getTraceFlags().asHex()`).

Those three pieces of information can be included in log statements produced by the logging library
by specifying them in the pattern/format.
by specifying them in the pattern/format.

Tip: for Spring Boot configuration which uses logback, you can add MDC to log lines by overriding only the `logging.pattern.level`:
```properties
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

package io.opentelemetry.instrumentation.api.instrumenter.code;

import static io.opentelemetry.instrumentation.api.internal.AttributesExtractorUtil.internalSet;

import io.opentelemetry.api.common.AttributesBuilder;
import io.opentelemetry.context.Context;
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
Expand Down Expand Up @@ -35,9 +37,9 @@ private CodeAttributesExtractor(CodeAttributesGetter<REQUEST> getter) {
public void onStart(AttributesBuilder attributes, Context parentContext, REQUEST request) {
Class<?> cls = getter.codeClass(request);
if (cls != null) {
set(attributes, SemanticAttributes.CODE_NAMESPACE, cls.getName());
internalSet(attributes, SemanticAttributes.CODE_NAMESPACE, cls.getName());
}
set(attributes, SemanticAttributes.CODE_FUNCTION, getter.methodName(request));
internalSet(attributes, SemanticAttributes.CODE_FUNCTION, getter.methodName(request));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

package io.opentelemetry.instrumentation.api.instrumenter.db;

import static io.opentelemetry.instrumentation.api.internal.AttributesExtractorUtil.internalSet;

import io.opentelemetry.api.common.AttributesBuilder;
import io.opentelemetry.context.Context;
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
Expand Down Expand Up @@ -35,7 +37,7 @@ public static <REQUEST, RESPONSE> DbClientAttributesExtractor<REQUEST, RESPONSE>
public void onStart(AttributesBuilder attributes, Context parentContext, REQUEST request) {
super.onStart(attributes, parentContext, request);

set(attributes, SemanticAttributes.DB_STATEMENT, getter.statement(request));
set(attributes, SemanticAttributes.DB_OPERATION, getter.operation(request));
internalSet(attributes, SemanticAttributes.DB_STATEMENT, getter.statement(request));
internalSet(attributes, SemanticAttributes.DB_OPERATION, getter.operation(request));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

package io.opentelemetry.instrumentation.api.instrumenter.db;

import static io.opentelemetry.instrumentation.api.internal.AttributesExtractorUtil.internalSet;

import io.opentelemetry.api.common.AttributesBuilder;
import io.opentelemetry.context.Context;
import io.opentelemetry.instrumentation.api.annotations.UnstableApi;
Expand All @@ -26,10 +28,11 @@ abstract class DbClientCommonAttributesExtractor<

@Override
public void onStart(AttributesBuilder attributes, Context parentContext, REQUEST request) {
set(attributes, SemanticAttributes.DB_SYSTEM, getter.system(request));
set(attributes, SemanticAttributes.DB_USER, getter.user(request));
set(attributes, SemanticAttributes.DB_NAME, getter.name(request));
set(attributes, SemanticAttributes.DB_CONNECTION_STRING, getter.connectionString(request));
internalSet(attributes, SemanticAttributes.DB_SYSTEM, getter.system(request));
internalSet(attributes, SemanticAttributes.DB_USER, getter.user(request));
internalSet(attributes, SemanticAttributes.DB_NAME, getter.name(request));
internalSet(
attributes, SemanticAttributes.DB_CONNECTION_STRING, getter.connectionString(request));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

package io.opentelemetry.instrumentation.api.instrumenter.db;

import static io.opentelemetry.instrumentation.api.internal.AttributesExtractorUtil.internalSet;

import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.common.AttributesBuilder;
import io.opentelemetry.context.Context;
Expand Down Expand Up @@ -55,8 +57,8 @@ public void onStart(AttributesBuilder attributes, Context parentContext, REQUEST

SqlStatementInfo sanitizedStatement =
SqlStatementSanitizer.sanitize(getter.rawStatement(request));
set(attributes, SemanticAttributes.DB_STATEMENT, sanitizedStatement.getFullStatement());
set(attributes, SemanticAttributes.DB_OPERATION, sanitizedStatement.getOperation());
set(attributes, dbTableAttribute, sanitizedStatement.getTable());
internalSet(attributes, SemanticAttributes.DB_STATEMENT, sanitizedStatement.getFullStatement());
internalSet(attributes, SemanticAttributes.DB_OPERATION, sanitizedStatement.getOperation());
internalSet(attributes, dbTableAttribute, sanitizedStatement.getTable());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

package io.opentelemetry.instrumentation.api.instrumenter.http;

import static io.opentelemetry.instrumentation.api.internal.AttributesExtractorUtil.internalSet;

import io.opentelemetry.api.common.AttributesBuilder;
import io.opentelemetry.context.Context;
import io.opentelemetry.instrumentation.api.annotations.UnstableApi;
Expand Down Expand Up @@ -53,7 +55,7 @@ public static <REQUEST, RESPONSE> HttpClientAttributesExtractorBuilder<REQUEST,
@Override
public void onStart(AttributesBuilder attributes, Context parentContext, REQUEST request) {
super.onStart(attributes, parentContext, request);
set(attributes, SemanticAttributes.HTTP_URL, getter.url(request));
internalSet(attributes, SemanticAttributes.HTTP_URL, getter.url(request));
}

@Override
Expand All @@ -64,7 +66,7 @@ public void onEnd(
@Nullable RESPONSE response,
@Nullable Throwable error) {
super.onEnd(attributes, context, request, response, error);
set(attributes, SemanticAttributes.HTTP_FLAVOR, getter.flavor(request, response));
internalSet(attributes, SemanticAttributes.HTTP_FLAVOR, getter.flavor(request, response));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import static io.opentelemetry.instrumentation.api.instrumenter.http.CapturedHttpHeadersUtil.lowercase;
import static io.opentelemetry.instrumentation.api.instrumenter.http.CapturedHttpHeadersUtil.requestAttributeKey;
import static io.opentelemetry.instrumentation.api.instrumenter.http.CapturedHttpHeadersUtil.responseAttributeKey;
import static io.opentelemetry.instrumentation.api.internal.AttributesExtractorUtil.internalSet;

import io.opentelemetry.api.common.AttributesBuilder;
import io.opentelemetry.context.Context;
Expand Down Expand Up @@ -38,13 +39,13 @@ abstract class HttpCommonAttributesExtractor<

@Override
public void onStart(AttributesBuilder attributes, Context parentContext, REQUEST request) {
set(attributes, SemanticAttributes.HTTP_METHOD, getter.method(request));
set(attributes, SemanticAttributes.HTTP_USER_AGENT, userAgent(request));
internalSet(attributes, SemanticAttributes.HTTP_METHOD, getter.method(request));
internalSet(attributes, SemanticAttributes.HTTP_USER_AGENT, userAgent(request));

for (String name : capturedRequestHeaders) {
List<String> values = getter.requestHeader(request, name);
if (!values.isEmpty()) {
set(attributes, requestAttributeKey(name), values);
internalSet(attributes, requestAttributeKey(name), values);
}
}
}
Expand All @@ -57,33 +58,33 @@ public void onEnd(
@Nullable RESPONSE response,
@Nullable Throwable error) {

set(
internalSet(
attributes,
SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH,
getter.requestContentLength(request, response));
set(
internalSet(
attributes,
SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH_UNCOMPRESSED,
getter.requestContentLengthUncompressed(request, response));

if (response != null) {
Integer statusCode = getter.statusCode(request, response);
if (statusCode != null && statusCode > 0) {
set(attributes, SemanticAttributes.HTTP_STATUS_CODE, (long) statusCode);
internalSet(attributes, SemanticAttributes.HTTP_STATUS_CODE, (long) statusCode);
}
set(
internalSet(
attributes,
SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH,
getter.responseContentLength(request, response));
set(
internalSet(
attributes,
SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH_UNCOMPRESSED,
getter.responseContentLengthUncompressed(request, response));

for (String name : capturedResponseHeaders) {
List<String> values = getter.responseHeader(request, response, name);
if (!values.isEmpty()) {
set(attributes, responseAttributeKey(name), values);
internalSet(attributes, responseAttributeKey(name), values);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import static io.opentelemetry.instrumentation.api.instrumenter.http.ForwardedHeaderParser.extractClientIpFromForwardedHeader;
import static io.opentelemetry.instrumentation.api.instrumenter.http.ForwardedHeaderParser.extractProtoFromForwardedHeader;
import static io.opentelemetry.instrumentation.api.instrumenter.http.ForwardedHeaderParser.extractProtoFromForwardedProtoHeader;
import static io.opentelemetry.instrumentation.api.internal.AttributesExtractorUtil.internalSet;

import io.opentelemetry.api.common.AttributesBuilder;
import io.opentelemetry.context.Context;
Expand Down Expand Up @@ -68,17 +69,15 @@ public static <REQUEST, RESPONSE> HttpServerAttributesExtractorBuilder<REQUEST,
public void onStart(AttributesBuilder attributes, Context parentContext, REQUEST request) {
super.onStart(attributes, parentContext, request);

set(attributes, SemanticAttributes.HTTP_FLAVOR, getter.flavor(request));
internalSet(attributes, SemanticAttributes.HTTP_FLAVOR, getter.flavor(request));
String forwardedProto = forwardedProto(request);
set(
attributes,
SemanticAttributes.HTTP_SCHEME,
forwardedProto != null ? forwardedProto : getter.scheme(request));
set(attributes, SemanticAttributes.HTTP_HOST, host(request));
set(attributes, SemanticAttributes.HTTP_TARGET, getter.target(request));
set(attributes, SemanticAttributes.HTTP_ROUTE, getter.route(request));
set(attributes, SemanticAttributes.HTTP_SERVER_NAME, getter.serverName(request));
set(attributes, SemanticAttributes.HTTP_CLIENT_IP, clientIp(request));
String value = forwardedProto != null ? forwardedProto : getter.scheme(request);
internalSet(attributes, SemanticAttributes.HTTP_SCHEME, value);
internalSet(attributes, SemanticAttributes.HTTP_HOST, host(request));
internalSet(attributes, SemanticAttributes.HTTP_TARGET, getter.target(request));
internalSet(attributes, SemanticAttributes.HTTP_ROUTE, getter.route(request));
internalSet(attributes, SemanticAttributes.HTTP_SERVER_NAME, getter.serverName(request));
internalSet(attributes, SemanticAttributes.HTTP_CLIENT_IP, clientIp(request));
}

@Override
Expand All @@ -90,7 +89,7 @@ public void onEnd(
@Nullable Throwable error) {

super.onEnd(attributes, context, request, response, error);
set(attributes, SemanticAttributes.HTTP_ROUTE, httpRouteHolderGetter.apply(context));
internalSet(attributes, SemanticAttributes.HTTP_ROUTE, httpRouteHolderGetter.apply(context));
}

@Nullable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import static io.opentelemetry.instrumentation.api.instrumenter.messaging.MessageOperation.PROCESS;
import static io.opentelemetry.instrumentation.api.instrumenter.messaging.MessageOperation.RECEIVE;
import static io.opentelemetry.instrumentation.api.internal.AttributesExtractorUtil.internalSet;

import io.opentelemetry.api.common.AttributesBuilder;
import io.opentelemetry.context.Context;
Expand Down Expand Up @@ -50,29 +51,33 @@ private MessagingAttributesExtractor(
@SuppressWarnings("deprecation") // operationName
@Override
public void onStart(AttributesBuilder attributes, Context parentContext, REQUEST request) {
set(attributes, SemanticAttributes.MESSAGING_SYSTEM, getter.system(request));
set(attributes, SemanticAttributes.MESSAGING_DESTINATION_KIND, getter.destinationKind(request));
internalSet(attributes, SemanticAttributes.MESSAGING_SYSTEM, getter.system(request));
internalSet(
attributes, SemanticAttributes.MESSAGING_DESTINATION_KIND, getter.destinationKind(request));
boolean isTemporaryDestination = getter.temporaryDestination(request);
if (isTemporaryDestination) {
set(attributes, SemanticAttributes.MESSAGING_TEMP_DESTINATION, true);
set(attributes, SemanticAttributes.MESSAGING_DESTINATION, TEMP_DESTINATION_NAME);
internalSet(attributes, SemanticAttributes.MESSAGING_TEMP_DESTINATION, true);
internalSet(attributes, SemanticAttributes.MESSAGING_DESTINATION, TEMP_DESTINATION_NAME);
} else {
set(attributes, SemanticAttributes.MESSAGING_DESTINATION, getter.destination(request));
internalSet(
attributes, SemanticAttributes.MESSAGING_DESTINATION, getter.destination(request));
}
set(attributes, SemanticAttributes.MESSAGING_PROTOCOL, getter.protocol(request));
set(attributes, SemanticAttributes.MESSAGING_PROTOCOL_VERSION, getter.protocolVersion(request));
set(attributes, SemanticAttributes.MESSAGING_URL, getter.url(request));
set(attributes, SemanticAttributes.MESSAGING_CONVERSATION_ID, getter.conversationId(request));
set(
internalSet(attributes, SemanticAttributes.MESSAGING_PROTOCOL, getter.protocol(request));
internalSet(
attributes, SemanticAttributes.MESSAGING_PROTOCOL_VERSION, getter.protocolVersion(request));
internalSet(attributes, SemanticAttributes.MESSAGING_URL, getter.url(request));
internalSet(
attributes, SemanticAttributes.MESSAGING_CONVERSATION_ID, getter.conversationId(request));
internalSet(
attributes,
SemanticAttributes.MESSAGING_MESSAGE_PAYLOAD_SIZE_BYTES,
getter.messagePayloadSize(request));
set(
internalSet(
attributes,
SemanticAttributes.MESSAGING_MESSAGE_PAYLOAD_COMPRESSED_SIZE_BYTES,
getter.messagePayloadCompressedSize(request));
if (operation == RECEIVE || operation == PROCESS) {
set(attributes, SemanticAttributes.MESSAGING_OPERATION, operation.operationName());
internalSet(attributes, SemanticAttributes.MESSAGING_OPERATION, operation.operationName());
}
}

Expand All @@ -83,7 +88,8 @@ public void onEnd(
REQUEST request,
@Nullable RESPONSE response,
@Nullable Throwable error) {
set(attributes, SemanticAttributes.MESSAGING_MESSAGE_ID, getter.messageId(request, response));
internalSet(
attributes, SemanticAttributes.MESSAGING_MESSAGE_ID, getter.messageId(request, response));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

package io.opentelemetry.instrumentation.api.instrumenter.net;

import static io.opentelemetry.instrumentation.api.internal.AttributesExtractorUtil.internalSet;

import io.opentelemetry.api.common.AttributesBuilder;
import io.opentelemetry.context.Context;
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
Expand Down Expand Up @@ -45,19 +47,19 @@ public void onEnd(
@Nullable RESPONSE response,
@Nullable Throwable error) {

set(attributes, SemanticAttributes.NET_TRANSPORT, getter.transport(request, response));
internalSet(attributes, SemanticAttributes.NET_TRANSPORT, getter.transport(request, response));

String peerIp = getter.peerIp(request, response);
String peerName = getter.peerName(request, response);

if (peerName != null && !peerName.equals(peerIp)) {
set(attributes, SemanticAttributes.NET_PEER_NAME, peerName);
internalSet(attributes, SemanticAttributes.NET_PEER_NAME, peerName);
}
set(attributes, SemanticAttributes.NET_PEER_IP, peerIp);
internalSet(attributes, SemanticAttributes.NET_PEER_IP, peerIp);

Integer peerPort = getter.peerPort(request, response);
if (peerPort != null && peerPort > 0) {
set(attributes, SemanticAttributes.NET_PEER_PORT, (long) peerPort);
internalSet(attributes, SemanticAttributes.NET_PEER_PORT, (long) peerPort);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

package io.opentelemetry.instrumentation.api.instrumenter.net;

import static io.opentelemetry.instrumentation.api.internal.AttributesExtractorUtil.internalSet;

import io.opentelemetry.api.common.AttributesBuilder;
import io.opentelemetry.context.Context;
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
Expand Down Expand Up @@ -33,15 +35,15 @@ private NetServerAttributesExtractor(NetServerAttributesGetter<REQUEST> getter)

@Override
public void onStart(AttributesBuilder attributes, Context parentContext, REQUEST request) {
set(attributes, SemanticAttributes.NET_TRANSPORT, getter.transport(request));
internalSet(attributes, SemanticAttributes.NET_TRANSPORT, getter.transport(request));

String peerIp = getter.peerIp(request);

set(attributes, SemanticAttributes.NET_PEER_IP, peerIp);
internalSet(attributes, SemanticAttributes.NET_PEER_IP, peerIp);

Integer peerPort = getter.peerPort(request);
if (peerPort != null && peerPort > 0) {
set(attributes, SemanticAttributes.NET_PEER_PORT, (long) peerPort);
internalSet(attributes, SemanticAttributes.NET_PEER_PORT, (long) peerPort);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

package io.opentelemetry.instrumentation.api.instrumenter.rpc;

import static io.opentelemetry.instrumentation.api.internal.AttributesExtractorUtil.internalSet;

import io.opentelemetry.api.common.AttributesBuilder;
import io.opentelemetry.context.Context;
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
Expand All @@ -22,9 +24,9 @@ abstract class RpcCommonAttributesExtractor<REQUEST, RESPONSE>

@Override
public final void onStart(AttributesBuilder attributes, Context parentContext, REQUEST request) {
set(attributes, SemanticAttributes.RPC_SYSTEM, getter.system(request));
set(attributes, SemanticAttributes.RPC_SERVICE, getter.service(request));
set(attributes, SemanticAttributes.RPC_METHOD, getter.method(request));
internalSet(attributes, SemanticAttributes.RPC_SYSTEM, getter.system(request));
internalSet(attributes, SemanticAttributes.RPC_SERVICE, getter.service(request));
internalSet(attributes, SemanticAttributes.RPC_METHOD, getter.method(request));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ void onEnd(
/**
* Sets the {@code value} with the given {@code key} to the {@link AttributesBuilder} if {@code
* value} is not {@code null}.
*
* @deprecated This method will be removed.
*/
// TODO: remove after 1.13 release
@Deprecated
default <T> void set(AttributesBuilder attributes, AttributeKey<T> key, @Nullable T value) {
if (value != null) {
attributes.put(key, value);
Expand Down
Loading