Skip to content
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 aws-xray/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ dependencies {

implementation("com.squareup.okhttp3:okhttp")
implementation("io.opentelemetry.semconv:opentelemetry-semconv")
implementation("io.opentelemetry.semconv:opentelemetry-semconv-incubating")
testImplementation("io.opentelemetry.semconv:opentelemetry-semconv-incubating")

annotationProcessor("com.google.auto.service:auto-service")
testImplementation("com.google.auto.service:auto-service")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,6 @@
import static io.opentelemetry.contrib.awsxray.AwsAttributeKeys.AWS_STREAM_NAME;
import static io.opentelemetry.contrib.awsxray.AwsAttributeKeys.AWS_TABLE_NAME;
import static io.opentelemetry.semconv.ServiceAttributes.SERVICE_NAME;
import static io.opentelemetry.semconv.incubating.DbIncubatingAttributes.DB_OPERATION;
import static io.opentelemetry.semconv.incubating.DbIncubatingAttributes.DB_SYSTEM;
import static io.opentelemetry.semconv.incubating.FaasIncubatingAttributes.FAAS_INVOKED_NAME;
import static io.opentelemetry.semconv.incubating.FaasIncubatingAttributes.FAAS_TRIGGER;
import static io.opentelemetry.semconv.incubating.GraphqlIncubatingAttributes.GRAPHQL_OPERATION_TYPE;
import static io.opentelemetry.semconv.incubating.HttpIncubatingAttributes.HTTP_METHOD;
import static io.opentelemetry.semconv.incubating.HttpIncubatingAttributes.HTTP_TARGET;
import static io.opentelemetry.semconv.incubating.HttpIncubatingAttributes.HTTP_URL;
import static io.opentelemetry.semconv.incubating.MessagingIncubatingAttributes.MESSAGING_OPERATION;
import static io.opentelemetry.semconv.incubating.MessagingIncubatingAttributes.MESSAGING_SYSTEM;
import static io.opentelemetry.semconv.incubating.NetIncubatingAttributes.NET_PEER_NAME;
import static io.opentelemetry.semconv.incubating.NetIncubatingAttributes.NET_PEER_PORT;
import static io.opentelemetry.semconv.incubating.NetIncubatingAttributes.NET_SOCK_PEER_ADDR;
import static io.opentelemetry.semconv.incubating.NetIncubatingAttributes.NET_SOCK_PEER_PORT;
import static io.opentelemetry.semconv.incubating.PeerIncubatingAttributes.PEER_SERVICE;
import static io.opentelemetry.semconv.incubating.RpcIncubatingAttributes.RPC_METHOD;
import static io.opentelemetry.semconv.incubating.RpcIncubatingAttributes.RPC_SERVICE;

import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.common.Attributes;
Expand All @@ -41,7 +24,6 @@
import io.opentelemetry.sdk.resources.Resource;
import io.opentelemetry.sdk.trace.data.SpanData;
import io.opentelemetry.semconv.ServiceAttributes;
import io.opentelemetry.semconv.incubating.GraphqlIncubatingAttributes;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Optional;
Expand All @@ -57,7 +39,6 @@
* represent "incoming" traffic, {@link SpanKind#CLIENT} and {@link SpanKind#PRODUCER} spans
* represent "outgoing" traffic, and {@link SpanKind#INTERNAL} spans are ignored.
*/
@SuppressWarnings("deprecation") // uses deprecated semantic conventions
final class AwsMetricAttributeGenerator implements MetricAttributeGenerator {

private static final Logger logger =
Expand All @@ -72,6 +53,38 @@ final class AwsMetricAttributeGenerator implements MetricAttributeGenerator {
private static final String UNKNOWN_REMOTE_SERVICE = "UnknownRemoteService";
private static final String UNKNOWN_REMOTE_OPERATION = "UnknownRemoteOperation";

// copied from DbIncubatingAttributes
private static final AttributeKey<String> DB_OPERATION = AttributeKey.stringKey("db.operation");
private static final AttributeKey<String> DB_SYSTEM = AttributeKey.stringKey("db.system");
// copied from FaasIncubatingAttributes
private static final AttributeKey<String> FAAS_INVOKED_NAME =
AttributeKey.stringKey("faas.invoked_name");
private static final AttributeKey<String> FAAS_TRIGGER = AttributeKey.stringKey("faas.trigger");
// copied from GraphqlIncubatingAttributes
private static final AttributeKey<String> GRAPHQL_OPERATION_TYPE =
AttributeKey.stringKey("graphql.operation.type");
// copied from HttpIncubatingAttributes
private static final AttributeKey<String> HTTP_METHOD = AttributeKey.stringKey("http.method");
private static final AttributeKey<String> HTTP_TARGET = AttributeKey.stringKey("http.target");
private static final AttributeKey<String> HTTP_URL = AttributeKey.stringKey("http.url");
// copied from MessagingIncubatingAttributes
private static final AttributeKey<String> MESSAGING_OPERATION =
AttributeKey.stringKey("messaging.operation");
private static final AttributeKey<String> MESSAGING_SYSTEM =
AttributeKey.stringKey("messaging.system");
// copied from NetIncubatingAttributes
private static final AttributeKey<String> NET_PEER_NAME = AttributeKey.stringKey("net.peer.name");
private static final AttributeKey<Long> NET_PEER_PORT = AttributeKey.longKey("net.peer.port");
private static final AttributeKey<String> NET_SOCK_PEER_ADDR =
AttributeKey.stringKey("net.sock.peer.addr");
private static final AttributeKey<Long> NET_SOCK_PEER_PORT =
AttributeKey.longKey("net.sock.peer.port");
// copied from PeerIncubatingAttributes
private static final AttributeKey<String> PEER_SERVICE = AttributeKey.stringKey("peer.service");
// copied from RpcIncubatingAttributes
private static final AttributeKey<String> RPC_METHOD = AttributeKey.stringKey("rpc.method");
private static final AttributeKey<String> RPC_SERVICE = AttributeKey.stringKey("rpc.service");

@Override
public Attributes generateMetricAttributesFromSpan(SpanData span, Resource resource) {
AttributesBuilder builder = Attributes.builder();
Expand Down Expand Up @@ -196,8 +209,8 @@ private static void setEgressOperation(SpanData span, AttributesBuilder builder)
* <li>DB
* <li>FAAS
* <li>Messaging
* <li>GraphQL - Special case, if {@link GraphqlIncubatingAttributes#GRAPHQL_OPERATION_TYPE} is
* present, we use it for RemoteOperation and set RemoteService to {@link #GRAPHQL}.
* <li>GraphQL - Special case, if {@link #GRAPHQL_OPERATION_TYPE} is present, we use it for
* RemoteOperation and set RemoteService to {@link #GRAPHQL}.
* </ul>
*
* <p>In each case, these span attributes were selected from the OpenTelemetry trace semantic
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@

package io.opentelemetry.contrib.awsxray;

import static io.opentelemetry.semconv.incubating.HttpIncubatingAttributes.HTTP_STATUS_CODE;

import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.metrics.DoubleHistogram;
import io.opentelemetry.api.metrics.LongCounter;
Expand Down Expand Up @@ -39,9 +38,11 @@
* AlwaysRecordSampler}, which will result in 100% of spans being sent to the processor.
*/
@Immutable
@SuppressWarnings("deprecation") // uses deprecated semantic conventions
public final class AwsSpanMetricsProcessor implements SpanProcessor {

private static final AttributeKey<Long> HTTP_STATUS_CODE =
AttributeKey.longKey("http.status_code");

private static final double NANOS_TO_MILLIS = 1_000_000.0;

// Constants for deriving error and fault metrics
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,6 @@
package io.opentelemetry.contrib.awsxray;

import static io.opentelemetry.semconv.ServiceAttributes.SERVICE_NAME;
import static io.opentelemetry.semconv.incubating.AwsIncubatingAttributes.AWS_ECS_CONTAINER_ARN;
import static io.opentelemetry.semconv.incubating.CloudIncubatingAttributes.CLOUD_PLATFORM;
import static io.opentelemetry.semconv.incubating.CloudIncubatingAttributes.CLOUD_RESOURCE_ID;
import static io.opentelemetry.semconv.incubating.HttpIncubatingAttributes.HTTP_HOST;
import static io.opentelemetry.semconv.incubating.HttpIncubatingAttributes.HTTP_METHOD;
import static io.opentelemetry.semconv.incubating.HttpIncubatingAttributes.HTTP_TARGET;
import static io.opentelemetry.semconv.incubating.HttpIncubatingAttributes.HTTP_URL;
import static io.opentelemetry.semconv.incubating.NetIncubatingAttributes.NET_HOST_NAME;

import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.common.Attributes;
Expand All @@ -27,7 +19,6 @@
import io.opentelemetry.sdk.trace.samplers.Sampler;
import io.opentelemetry.sdk.trace.samplers.SamplingDecision;
import io.opentelemetry.sdk.trace.samplers.SamplingResult;
import io.opentelemetry.semconv.incubating.CloudIncubatingAttributes;
import java.time.Duration;
import java.util.Collections;
import java.util.Date;
Expand All @@ -42,22 +33,37 @@

final class SamplingRuleApplier {

// copied from AwsIncubatingAttributes
private static final AttributeKey<String> AWS_ECS_CONTAINER_ARN =
AttributeKey.stringKey("aws.ecs.container.arn");
// copied from CloudIncubatingAttributes
private static final AttributeKey<String> CLOUD_PLATFORM =
AttributeKey.stringKey("cloud.platform");
private static final AttributeKey<String> CLOUD_RESOURCE_ID =
AttributeKey.stringKey("cloud.resource_id");
// copied from CloudIncubatingAttributes.CloudPlatformIncubatingValues
public static final String AWS_EC2 = "aws_ec2";
public static final String AWS_ECS = "aws_ecs";
public static final String AWS_EKS = "aws_eks";
public static final String AWS_LAMBDA = "aws_lambda";
public static final String AWS_ELASTIC_BEANSTALK = "aws_elastic_beanstalk";
// copied from HttpIncubatingAttributes
private static final AttributeKey<String> HTTP_HOST = AttributeKey.stringKey("http.host");
private static final AttributeKey<String> HTTP_METHOD = AttributeKey.stringKey("http.method");
private static final AttributeKey<String> HTTP_TARGET = AttributeKey.stringKey("http.target");
private static final AttributeKey<String> HTTP_URL = AttributeKey.stringKey("http.url");
// copied from NetIncubatingAttributes
private static final AttributeKey<String> NET_HOST_NAME = AttributeKey.stringKey("net.host.name");

private static final Map<String, String> XRAY_CLOUD_PLATFORM;

static {
Map<String, String> xrayCloudPlatform = new HashMap<>();
xrayCloudPlatform.put(
CloudIncubatingAttributes.CloudPlatformIncubatingValues.AWS_EC2, "AWS::EC2::Instance");
xrayCloudPlatform.put(
CloudIncubatingAttributes.CloudPlatformIncubatingValues.AWS_ECS, "AWS::ECS::Container");
xrayCloudPlatform.put(
CloudIncubatingAttributes.CloudPlatformIncubatingValues.AWS_EKS, "AWS::EKS::Container");
xrayCloudPlatform.put(
CloudIncubatingAttributes.CloudPlatformIncubatingValues.AWS_ELASTIC_BEANSTALK,
"AWS::ElasticBeanstalk::Environment");
xrayCloudPlatform.put(
CloudIncubatingAttributes.CloudPlatformIncubatingValues.AWS_LAMBDA,
"AWS::Lambda::Function");
xrayCloudPlatform.put(AWS_EC2, "AWS::EC2::Instance");
xrayCloudPlatform.put(AWS_ECS, "AWS::ECS::Container");
xrayCloudPlatform.put(AWS_EKS, "AWS::EKS::Container");
xrayCloudPlatform.put(AWS_ELASTIC_BEANSTALK, "AWS::ElasticBeanstalk::Environment");
xrayCloudPlatform.put(AWS_LAMBDA, "AWS::Lambda::Function");
XRAY_CLOUD_PLATFORM = Collections.unmodifiableMap(xrayCloudPlatform);
}

Expand Down Expand Up @@ -348,7 +354,7 @@ private static String getArn(Attributes attributes, Resource resource) {
return arn;
}
String cloudPlatform = resource.getAttributes().get(CLOUD_PLATFORM);
if (CloudIncubatingAttributes.CloudPlatformIncubatingValues.AWS_LAMBDA.equals(cloudPlatform)) {
if (AWS_LAMBDA.equals(cloudPlatform)) {
return getLambdaArn(attributes, resource);
}
return null;
Expand Down
Loading