Skip to content

Commit 2d9ca24

Browse files
committed
Addressed review comments
Signed-off-by: Krishna Kondaka <krishkdk@amazon.com>
1 parent bb5fc82 commit 2d9ca24

File tree

11 files changed

+585
-177
lines changed

11 files changed

+585
-177
lines changed

data-prepper-plugins/otel-apm-service-map-processor/src/main/java/org/opensearch/dataprepper/plugins/processor/otel_apm_service_map/model/internal/SpanStateData.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import java.util.Map;
2020
import java.util.Objects;
2121

22-
// TODO : 1. Add new rules as per Producer/Consumers/LocalRoot
2322
@Getter
2423
public class SpanStateData implements Serializable {
2524
private String serviceName;

data-prepper-plugins/otel-proto-common/src/main/java/org/opensearch/dataprepper/plugins/otel/common/OTelSpanDerivationUtil.java

Lines changed: 117 additions & 122 deletions
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright OpenSearch Contributors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* The OpenSearch Contributors require contributions made to
6+
* this file be licensed under the Apache-2.0 license or a
7+
* compatible open source license.
8+
*
9+
*/
10+
11+
package org.opensearch.dataprepper.plugins.otel.common;
12+
13+
public class RemoteOperationAndService {
14+
final String remoteService;
15+
final String remoteOperation;
16+
public RemoteOperationAndService(final String remoteOperation, final String remoteService) {
17+
this.remoteOperation = remoteOperation;
18+
this.remoteService = remoteService;
19+
}
20+
21+
public String getOperation() {
22+
return remoteOperation;
23+
}
24+
25+
public String getService() {
26+
return remoteService;
27+
}
28+
29+
public boolean isNull() {
30+
return remoteOperation == null || remoteService == null;
31+
}
32+
}
33+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
/*
2+
* Copyright OpenSearch Contributors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* The OpenSearch Contributors require contributions made to
6+
* this file be licensed under the Apache-2.0 license or a
7+
* compatible open source license.
8+
*
9+
*/
10+
11+
package org.opensearch.dataprepper.plugins.otel.common;
12+
13+
import static org.opensearch.dataprepper.plugins.otel.common.OTelSpanDerivationUtil.getStringAttribute;
14+
15+
import java.util.Map;
16+
17+
public class RemoteOperationAndServiceProviders {
18+
public final PeerServiceRemoteOperationServiceExtractor PeerServiceRemoteOperationServiceExtractor = new PeerServiceRemoteOperationServiceExtractor();
19+
public final GraphQlRemoteOperationServiceExtractor GraphQlRemoteOperationServiceExtractor = new GraphQlRemoteOperationServiceExtractor();
20+
public final MessagingSystemRemoteOperationServiceExtractor MessagingSystemRemoteOperationServiceExtractor = new MessagingSystemRemoteOperationServiceExtractor();
21+
public final FaasRemoteOperationServiceExtractor FaasRemoteOperationServiceExtractor = new FaasRemoteOperationServiceExtractor();
22+
public final DbRemoteOperationServiceExtractor DbRemoteOperationServiceExtractor = new DbRemoteOperationServiceExtractor();
23+
public final DbQueryRemoteOperationServiceExtractor DbQueryRemoteOperationServiceExtractor = new DbQueryRemoteOperationServiceExtractor();
24+
public final AwsRpcRemoteOperationServiceExtractor AwsRpcRemoteOperationServiceExtractor = new AwsRpcRemoteOperationServiceExtractor();
25+
26+
private static boolean appliesToSpan(Map<String, Object> spanAttributes, final String attribute1) {
27+
return getStringAttribute(spanAttributes, attribute1) != null;
28+
}
29+
30+
private static boolean appliesToSpan(Map<String, Object> spanAttributes, final String attribute1, final String attribute2) {
31+
return getStringAttribute(spanAttributes, attribute1) != null || getStringAttribute(spanAttributes, attribute2) != null;
32+
}
33+
34+
private static boolean appliesToSpan(Map<String, Object> spanAttributes, final String attribute1, final String attribute2, final String attribute3) {
35+
return getStringAttribute(spanAttributes, attribute1) != null || getStringAttribute(spanAttributes, attribute2) != null || getStringAttribute(spanAttributes, attribute3) != null;
36+
}
37+
38+
public static class PeerServiceRemoteOperationServiceExtractor implements RemoteOperationServiceExtractor {
39+
public boolean appliesToSpan(Map<String, Object> spanAttributes) {
40+
return RemoteOperationAndServiceProviders.appliesToSpan(spanAttributes, "peer.service");
41+
}
42+
43+
public RemoteOperationAndService getRemoteOperationAndService(Map<String, Object> spanAttributes, Object optionalArg) {
44+
return new RemoteOperationAndService(null, getStringAttribute(spanAttributes, "peer.service"));
45+
}
46+
}
47+
48+
public static class GraphQlRemoteOperationServiceExtractor implements RemoteOperationServiceExtractor {
49+
public boolean appliesToSpan(Map<String, Object> spanAttributes) {
50+
return RemoteOperationAndServiceProviders.appliesToSpan(spanAttributes, "graphql.operation.type");
51+
}
52+
53+
public RemoteOperationAndService getRemoteOperationAndService(Map<String, Object> spanAttributes, Object optionalArg) {
54+
final String graphQLOperation = getStringAttribute(spanAttributes, "graphql.operation.type");
55+
if (graphQLOperation != null) {
56+
return new RemoteOperationAndService(graphQLOperation, "graphql");
57+
}
58+
return new RemoteOperationAndService(null, null);
59+
}
60+
}
61+
62+
public static class MessagingSystemRemoteOperationServiceExtractor implements RemoteOperationServiceExtractor {
63+
public boolean appliesToSpan(Map<String, Object> spanAttributes) {
64+
return RemoteOperationAndServiceProviders.appliesToSpan(spanAttributes, "messaging.system", "messaging.operation");
65+
}
66+
67+
public RemoteOperationAndService getRemoteOperationAndService(Map<String, Object> spanAttributes, Object optionalArg) {
68+
return new RemoteOperationAndService(getStringAttribute(spanAttributes, "messaging.operation"), getStringAttribute(spanAttributes, "messaging.system"));
69+
}
70+
}
71+
72+
public static class FaasRemoteOperationServiceExtractor implements RemoteOperationServiceExtractor {
73+
74+
public boolean appliesToSpan(Map<String, Object> spanAttributes) {
75+
return RemoteOperationAndServiceProviders.appliesToSpan(spanAttributes, "faas.invoked_name", "faas.trigger");
76+
}
77+
78+
public RemoteOperationAndService getRemoteOperationAndService(Map<String, Object> spanAttributes, Object optionalArg) {
79+
return new RemoteOperationAndService(getStringAttribute(spanAttributes, "faas.trigger"), getStringAttribute(spanAttributes, "faas.invoked_name"));
80+
}
81+
}
82+
83+
public static class DbRemoteOperationServiceExtractor implements RemoteOperationServiceExtractor {
84+
public boolean appliesToSpan(Map<String, Object> spanAttributes) {
85+
return RemoteOperationAndServiceProviders.appliesToSpan(spanAttributes, "db.system", "db.operation", "db.statment");
86+
}
87+
88+
public RemoteOperationAndService getRemoteOperationAndService(Map<String, Object> spanAttributes, Object optionalArg) {
89+
String remoteOperation = getStringAttribute(spanAttributes, "db.operation");
90+
if (remoteOperation == null) {
91+
remoteOperation = getStringAttribute(spanAttributes, "db.statement");
92+
}
93+
if (remoteOperation != null) {
94+
remoteOperation = remoteOperation.trim().split("\\s+")[0].toUpperCase();
95+
}
96+
return new RemoteOperationAndService(remoteOperation,
97+
getStringAttribute(spanAttributes, "db.system"));
98+
}
99+
}
100+
101+
public static class DbQueryRemoteOperationServiceExtractor implements RemoteOperationServiceExtractor {
102+
public boolean appliesToSpan(Map<String, Object> spanAttributes) {
103+
return RemoteOperationAndServiceProviders.appliesToSpan(spanAttributes, "db.system.name", "db.operation.name", "db.query.text");
104+
}
105+
106+
public RemoteOperationAndService getRemoteOperationAndService(Map<String, Object> spanAttributes, Object optionalArg) {
107+
String remoteOperation = getStringAttribute(spanAttributes, "db.operation.name");
108+
if (remoteOperation == null) {
109+
remoteOperation = getStringAttribute(spanAttributes, "db.query.text");
110+
}
111+
if (remoteOperation != null) {
112+
remoteOperation = remoteOperation.trim().split("\\s+")[0].toUpperCase();
113+
}
114+
return new RemoteOperationAndService(remoteOperation, getStringAttribute(spanAttributes, "db.system.name"));
115+
}
116+
}
117+
118+
public static class AwsRpcRemoteOperationServiceExtractor implements RemoteOperationServiceExtractor {
119+
public boolean appliesToSpan(Map<String, Object> spanAttributes) {
120+
return RemoteOperationAndServiceProviders.appliesToSpan(spanAttributes, "rpc.service", "rpc.method");
121+
}
122+
123+
public RemoteOperationAndService getRemoteOperationAndService(Map<String, Object> spanAttributes, Object awsServiceMappings) {
124+
String remoteService = null;
125+
String rpcService = getStringAttribute(spanAttributes, "rpc.service");
126+
String rpcSystem = getStringAttribute(spanAttributes, "rpc.system");
127+
if (rpcSystem != null && rpcSystem.equals("aws-api")) {
128+
remoteService = (String)((Map<String, Object>)awsServiceMappings).getOrDefault(rpcService, "AWS::" + rpcService);
129+
}
130+
return new RemoteOperationAndService(getStringAttribute(spanAttributes, "rpc.method"), remoteService);
131+
}
132+
}
133+
}
134+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
* Copyright OpenSearch Contributors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* The OpenSearch Contributors require contributions made to
6+
* this file be licensed under the Apache-2.0 license or a
7+
* compatible open source license.
8+
*
9+
*/
10+
11+
package org.opensearch.dataprepper.plugins.otel.common;
12+
13+
import java.util.Map;
14+
15+
public interface RemoteOperationServiceExtractor {
16+
boolean appliesToSpan(Map<String, Object> spanAttributes);
17+
RemoteOperationAndService getRemoteOperationAndService(Map<String, Object> spanAttributes, Object optionalArg);
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
* Copyright OpenSearch Contributors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* The OpenSearch Contributors require contributions made to
6+
* this file be licensed under the Apache-2.0 license or a
7+
* compatible open source license.
8+
*
9+
*/
10+
11+
package org.opensearch.dataprepper.plugins.otel.common;
12+
13+
import static org.opensearch.dataprepper.plugins.otel.common.OTelSpanDerivationUtil.getStringAttribute;
14+
import java.util.Map;
15+
16+
public class ServiceEnvironmentProviders {
17+
public static String getDeploymentEnvironment(final Map<String, Object> spanAttributes) {
18+
try {
19+
// Navigate: spanAttributes -> "resource" -> "attributes" -> deployment keys
20+
@SuppressWarnings("unchecked")
21+
Map<String, Object> resourceAttrs = (Map<String, Object>)
22+
((Map<String, Object>) spanAttributes.get("resource")).get("attributes");
23+
24+
// Extract from resource.attributes.deployment.environment.name
25+
String env = getStringAttribute(resourceAttrs, "deployment.environment.name");
26+
if (env != null && !env.trim().isEmpty()) {
27+
return env;
28+
}
29+
30+
// Fall back to resource.attributes.deployment.environment
31+
env = getStringAttribute(resourceAttrs, "deployment.environment");
32+
if (env != null && !env.trim().isEmpty()) {
33+
return env;
34+
}
35+
} catch (Exception ignored) {
36+
// Any navigation failure falls through to default
37+
}
38+
// Default: 'generic:default'
39+
return "generic:default";
40+
}
41+
42+
public static String getAwsServiceEnvironment(final Map<String, Object> spanAttributes) {
43+
try {
44+
String cloudPlatform = getStringAttribute(spanAttributes, "cloud.platform");
45+
if (cloudPlatform != null && cloudPlatform.equals("aws_api_gateway")) {
46+
return "api-gateway:"+getStringAttribute(spanAttributes, "aws.api_gateway.stage");
47+
}
48+
if (cloudPlatform != null && cloudPlatform.equals("aws_ec2")) {
49+
return "ec2:default";
50+
}
51+
String cloudResourceId = getStringAttribute(spanAttributes, "cloud.resource_id");
52+
String invokedArn = getStringAttribute(spanAttributes, "aws.lambda.invoked_arn");
53+
if (cloudResourceId != null && cloudResourceId.startsWith("arn:aws:lambda:") || invokedArn != null) {
54+
return "lambda:default";
55+
}
56+
57+
@SuppressWarnings("unchecked")
58+
Map<String, Object> resourceAttributes = (Map<String, Object>)
59+
((Map<String, Object>) spanAttributes.get("resource")).get("attributes");
60+
String cloudProvider = getStringAttribute(resourceAttributes, "cloud.provider");
61+
String faasName = getStringAttribute(resourceAttributes, "faas.name");
62+
if (cloudProvider != null && cloudProvider.equals("aws") && faasName != null) {
63+
return "lambda:default";
64+
}
65+
} catch (Exception ignored) {
66+
}
67+
return null;
68+
}
69+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
server.address,server.port
2+
net.peer.name,net.peer.port
3+
network.peer.address,network.peer.port
4+
net.sock.peer.addr,net.sock.peer.port
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
AmazonDynamoDBv2,AWS::DynamoDB
2+
DynamoDb,AWS::DynamoDB
3+
dynamodb,AWS::DynamoDB
4+
DynamoDBv2,AWS::DynamoDB
5+
sns,AWS::SNS
6+
AmazonSNS,AWS::SNS
7+
SimpleNotificationService,AWS::SNS
8+
Kinesis,AWS::Kinesis
9+
AmazonKinesis,AWS::Kinesis
10+
Amazon S3,AWS::S3
11+
S3,AWS::S3
12+
s3,AWS::S3

0 commit comments

Comments
 (0)