|
@@ -5,12 +5,12 @@
|
|
|
|
|
|
package io.opentelemetry.instrumentation.awslambdaevents.v2_2.internal;
|
|
|
|
|
|
+import static io.opentelemetry.instrumentation.api.internal.AttributesExtractorUtil.internalSet;
|
|
|
+import static io.opentelemetry.instrumentation.api.internal.HttpConstants._OTHER;
|
|
|
import static io.opentelemetry.instrumentation.awslambdacore.v1_0.internal.MapUtils.emptyIfNull;
|
|
|
import static io.opentelemetry.instrumentation.awslambdacore.v1_0.internal.MapUtils.lowercaseMap;
|
|
|
import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.FAAS_TRIGGER;
|
|
|
-import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.HTTP_METHOD;
|
|
|
import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.HTTP_STATUS_CODE;
|
|
|
-import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.HTTP_URL;
|
|
|
import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.USER_AGENT_ORIGINAL;
|
|
|
|
|
|
import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent;
|
|
@@ -18,16 +18,27 @@ import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent
|
|
|
import io.opentelemetry.api.common.AttributesBuilder;
|
|
|
import io.opentelemetry.context.Context;
|
|
|
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
|
|
|
+import io.opentelemetry.instrumentation.api.instrumenter.http.internal.HttpAttributes;
|
|
|
+import io.opentelemetry.instrumentation.api.instrumenter.url.internal.UrlAttributes;
|
|
|
+import io.opentelemetry.instrumentation.api.internal.SemconvStability;
|
|
|
import io.opentelemetry.instrumentation.awslambdacore.v1_0.AwsLambdaRequest;
|
|
|
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
|
|
|
import java.io.UnsupportedEncodingException;
|
|
|
import java.net.URLEncoder;
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
import java.util.Map;
|
|
|
+import java.util.Set;
|
|
|
import javax.annotation.Nullable;
|
|
|
|
|
|
final class ApiGatewayProxyAttributesExtractor
|
|
|
implements AttributesExtractor<AwsLambdaRequest, Object> {
|
|
|
+
|
|
|
+ private final Set<String> knownMethods;
|
|
|
+
|
|
|
+ ApiGatewayProxyAttributesExtractor(Set<String> knownMethods) {
|
|
|
+ this.knownMethods = knownMethods;
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public void onStart(
|
|
|
AttributesBuilder attributes, Context parentContext, AwsLambdaRequest request) {
|
|
@@ -38,16 +49,34 @@ final class ApiGatewayProxyAttributesExtractor
|
|
|
}
|
|
|
|
|
|
void onRequest(AttributesBuilder attributes, APIGatewayProxyRequestEvent request) {
|
|
|
- attributes.put(HTTP_METHOD, request.getHttpMethod());
|
|
|
+ String method = request.getHttpMethod();
|
|
|
+ if (SemconvStability.emitStableHttpSemconv()) {
|
|
|
+ if (method == null || knownMethods.contains(method)) {
|
|
|
+ internalSet(attributes, HttpAttributes.HTTP_REQUEST_METHOD, method);
|
|
|
+ } else {
|
|
|
+ internalSet(attributes, HttpAttributes.HTTP_REQUEST_METHOD, _OTHER);
|
|
|
+ internalSet(attributes, HttpAttributes.HTTP_REQUEST_METHOD_ORIGINAL, method);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (SemconvStability.emitOldHttpSemconv()) {
|
|
|
+ internalSet(attributes, SemanticAttributes.HTTP_METHOD, method);
|
|
|
+ }
|
|
|
|
|
|
Map<String, String> headers = lowercaseMap(request.getHeaders());
|
|
|
String userAgent = headers.get("user-agent");
|
|
|
if (userAgent != null) {
|
|
|
attributes.put(USER_AGENT_ORIGINAL, userAgent);
|
|
|
}
|
|
|
+
|
|
|
String httpUrl = getHttpUrl(request, headers);
|
|
|
if (httpUrl != null) {
|
|
|
- attributes.put(HTTP_URL, httpUrl);
|
|
|
+ if (SemconvStability.emitStableHttpSemconv()) {
|
|
|
+ internalSet(attributes, UrlAttributes.URL_FULL, httpUrl);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (SemconvStability.emitOldHttpSemconv()) {
|
|
|
+ internalSet(attributes, SemanticAttributes.HTTP_URL, httpUrl);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -97,6 +126,4 @@ final class ApiGatewayProxyAttributesExtractor
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- ApiGatewayProxyAttributesExtractor() {}
|
|
|
}
|