This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch code-massel-CAMEL-23352 in repository https://gitbox.apache.org/repos/asf/camel.git
commit 8333f01d8e7b14f4bb9d3552162b4e5912ec82ed Author: Andrea Cosentino <[email protected]> AuthorDate: Fri May 8 09:01:49 2026 +0200 CAMEL-23387: camel-telemetry - Add span decorators for AWS Athena, CloudWatch, KMS, MSK, Step Functions, Timestream, Redshift Data and CloudTrail (#23045) Third batch of AWS span decorators for camel-telemetry. Adds AbstractSpanDecorator implementations for aws2-athena, aws2-cw, aws2-kms, aws2-msk, aws2-step-functions, aws2-timestream, aws2-redshift-data; plus an AbstractMessagingSpanDecorator for the aws-cloudtrail consumer. Database/analytics decorators (Athena, Timestream, Redshift Data) set semantic-conventions tags db.system and db.name for uniform aggregation alongside DDB/JDBC/SQL/Mongo/Cassandra spans. Header constants are mirrored from each component's *Constants interface to avoid hard module dependencies, matching the convention from #23038 and #23040. After review, dropped keyId from KMS and username from CloudTrail to keep the trace-tag surface minimal. All 8 decorators registered in META-INF/services and covered by unit tests. CAMEL-23387 stays open; further AWS components will land in subsequent PRs. --- .../decorators/AwsAthenaSpanDecorator.java | 84 ++++++++++++++++++++++ .../decorators/AwsCloudtrailSpanDecorator.java | 65 +++++++++++++++++ .../telemetry/decorators/AwsCwSpanDecorator.java | 80 +++++++++++++++++++++ .../telemetry/decorators/AwsKmsSpanDecorator.java | 66 +++++++++++++++++ .../telemetry/decorators/AwsMskSpanDecorator.java | 73 +++++++++++++++++++ .../decorators/AwsRedshiftDataSpanDecorator.java | 77 ++++++++++++++++++++ .../decorators/AwsStepFunctionsSpanDecorator.java | 80 +++++++++++++++++++++ .../decorators/AwsTimestreamSpanDecorator.java | 70 ++++++++++++++++++ .../org.apache.camel.telemetry.SpanDecorator | 8 +++ .../decorators/AwsAthenaSpanDecoratorTest.java | 67 +++++++++++++++++ .../decorators/AwsCloudtrailSpanDecoratorTest.java | 68 ++++++++++++++++++ .../decorators/AwsCwSpanDecoratorTest.java | 64 +++++++++++++++++ .../decorators/AwsKmsSpanDecoratorTest.java | 58 +++++++++++++++ .../decorators/AwsMskSpanDecoratorTest.java | 61 ++++++++++++++++ .../AwsRedshiftDataSpanDecoratorTest.java | 65 +++++++++++++++++ .../AwsStepFunctionsSpanDecoratorTest.java | 66 +++++++++++++++++ .../decorators/AwsTimestreamSpanDecoratorTest.java | 61 ++++++++++++++++ 17 files changed, 1113 insertions(+) diff --git a/components/camel-telemetry/src/main/java/org/apache/camel/telemetry/decorators/AwsAthenaSpanDecorator.java b/components/camel-telemetry/src/main/java/org/apache/camel/telemetry/decorators/AwsAthenaSpanDecorator.java new file mode 100644 index 000000000000..f98506b382f8 --- /dev/null +++ b/components/camel-telemetry/src/main/java/org/apache/camel/telemetry/decorators/AwsAthenaSpanDecorator.java @@ -0,0 +1,84 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.camel.telemetry.decorators; + +import org.apache.camel.Endpoint; +import org.apache.camel.Exchange; +import org.apache.camel.telemetry.Span; +import org.apache.camel.telemetry.TagConstants; + +public class AwsAthenaSpanDecorator extends AbstractSpanDecorator { + + static final String ATHENA_OPERATION = "operation"; + static final String ATHENA_DATABASE = "database"; + static final String ATHENA_QUERY_EXECUTION_ID = "queryExecutionId"; + static final String ATHENA_WORK_GROUP = "workGroup"; + static final String ATHENA_QUERY_EXECUTION_STATE = "queryExecutionState"; + + /** + * Constants copied from {@link org.apache.camel.component.aws2.athena.Athena2Constants} + */ + static final String OPERATION = "CamelAwsAthenaOperation"; + static final String DATABASE = "CamelAwsAthenaDatabase"; + static final String QUERY_EXECUTION_ID = "CamelAwsAthenaQueryExecutionId"; + static final String WORK_GROUP = "CamelAwsAthenaWorkGroup"; + static final String QUERY_EXECUTION_STATE = "CamelAwsAthenaQueryExecutionState"; + + @Override + public String getComponent() { + return "aws2-athena"; + } + + @Override + public String getComponentClassName() { + return "org.apache.camel.component.aws2.athena.Athena2Component"; + } + + @Override + public void beforeTracingEvent(Span span, Exchange exchange, Endpoint endpoint) { + super.beforeTracingEvent(span, exchange, endpoint); + + span.setTag(TagConstants.DB_SYSTEM, "athena"); + + Object operation = exchange.getIn().getHeader(OPERATION); + if (operation != null) { + span.setTag(ATHENA_OPERATION, operation.toString()); + } + + String database = exchange.getIn().getHeader(DATABASE, String.class); + if (database != null) { + span.setTag(ATHENA_DATABASE, database); + span.setTag(TagConstants.DB_NAME, database); + } + + String queryExecutionId = exchange.getIn().getHeader(QUERY_EXECUTION_ID, String.class); + if (queryExecutionId != null) { + span.setTag(ATHENA_QUERY_EXECUTION_ID, queryExecutionId); + } + + String workGroup = exchange.getIn().getHeader(WORK_GROUP, String.class); + if (workGroup != null) { + span.setTag(ATHENA_WORK_GROUP, workGroup); + } + + Object queryExecutionState = exchange.getIn().getHeader(QUERY_EXECUTION_STATE); + if (queryExecutionState != null) { + span.setTag(ATHENA_QUERY_EXECUTION_STATE, queryExecutionState.toString()); + } + } + +} diff --git a/components/camel-telemetry/src/main/java/org/apache/camel/telemetry/decorators/AwsCloudtrailSpanDecorator.java b/components/camel-telemetry/src/main/java/org/apache/camel/telemetry/decorators/AwsCloudtrailSpanDecorator.java new file mode 100644 index 000000000000..0dc5e0f9040e --- /dev/null +++ b/components/camel-telemetry/src/main/java/org/apache/camel/telemetry/decorators/AwsCloudtrailSpanDecorator.java @@ -0,0 +1,65 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.camel.telemetry.decorators; + +import org.apache.camel.Endpoint; +import org.apache.camel.Exchange; +import org.apache.camel.telemetry.Span; + +public class AwsCloudtrailSpanDecorator extends AbstractMessagingSpanDecorator { + + static final String CLOUDTRAIL_EVENT_NAME = "eventName"; + static final String CLOUDTRAIL_EVENT_SOURCE = "eventSource"; + + /** + * Constants copied from {@link org.apache.camel.component.aws.cloudtrail.CloudtrailConstants} + */ + static final String EVENT_ID = "CamelAwsCloudTrailEventId"; + static final String EVENT_NAME = "CamelAwsCloudTrailEventName"; + static final String EVENT_SOURCE = "CamelAwsCloudTrailEventSource"; + + @Override + public String getComponent() { + return "aws-cloudtrail"; + } + + @Override + public String getComponentClassName() { + return "org.apache.camel.component.aws.cloudtrail.CloudtrailComponent"; + } + + @Override + public void beforeTracingEvent(Span span, Exchange exchange, Endpoint endpoint) { + super.beforeTracingEvent(span, exchange, endpoint); + + String eventName = exchange.getIn().getHeader(EVENT_NAME, String.class); + if (eventName != null) { + span.setTag(CLOUDTRAIL_EVENT_NAME, eventName); + } + + String eventSource = exchange.getIn().getHeader(EVENT_SOURCE, String.class); + if (eventSource != null) { + span.setTag(CLOUDTRAIL_EVENT_SOURCE, eventSource); + } + } + + @Override + protected String getMessageId(Exchange exchange) { + return exchange.getIn().getHeader(EVENT_ID, String.class); + } + +} diff --git a/components/camel-telemetry/src/main/java/org/apache/camel/telemetry/decorators/AwsCwSpanDecorator.java b/components/camel-telemetry/src/main/java/org/apache/camel/telemetry/decorators/AwsCwSpanDecorator.java new file mode 100644 index 000000000000..17b97fa6a263 --- /dev/null +++ b/components/camel-telemetry/src/main/java/org/apache/camel/telemetry/decorators/AwsCwSpanDecorator.java @@ -0,0 +1,80 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.camel.telemetry.decorators; + +import org.apache.camel.Endpoint; +import org.apache.camel.Exchange; +import org.apache.camel.telemetry.Span; + +public class AwsCwSpanDecorator extends AbstractSpanDecorator { + + static final String CW_OPERATION = "operation"; + static final String CW_METRIC_NAMESPACE = "metricNamespace"; + static final String CW_METRIC_NAME = "metricName"; + static final String CW_ALARM_NAME = "alarmName"; + static final String CW_ALARM_STATE = "alarmState"; + + /** + * Constants copied from {@link org.apache.camel.component.aws2.cw.Cw2Constants} + */ + static final String OPERATION = "CamelAwsCwOperation"; + static final String METRIC_NAMESPACE = "CamelAwsCwMetricNamespace"; + static final String METRIC_NAME = "CamelAwsCwMetricName"; + static final String ALARM_NAME = "CamelAwsCwAlarmName"; + static final String ALARM_STATE = "CamelAwsCwAlarmState"; + + @Override + public String getComponent() { + return "aws2-cw"; + } + + @Override + public String getComponentClassName() { + return "org.apache.camel.component.aws2.cw.Cw2Component"; + } + + @Override + public void beforeTracingEvent(Span span, Exchange exchange, Endpoint endpoint) { + super.beforeTracingEvent(span, exchange, endpoint); + + String operation = exchange.getIn().getHeader(OPERATION, String.class); + if (operation != null) { + span.setTag(CW_OPERATION, operation); + } + + String metricNamespace = exchange.getIn().getHeader(METRIC_NAMESPACE, String.class); + if (metricNamespace != null) { + span.setTag(CW_METRIC_NAMESPACE, metricNamespace); + } + + String metricName = exchange.getIn().getHeader(METRIC_NAME, String.class); + if (metricName != null) { + span.setTag(CW_METRIC_NAME, metricName); + } + + String alarmName = exchange.getIn().getHeader(ALARM_NAME, String.class); + if (alarmName != null) { + span.setTag(CW_ALARM_NAME, alarmName); + } + + String alarmState = exchange.getIn().getHeader(ALARM_STATE, String.class); + if (alarmState != null) { + span.setTag(CW_ALARM_STATE, alarmState); + } + } + +} diff --git a/components/camel-telemetry/src/main/java/org/apache/camel/telemetry/decorators/AwsKmsSpanDecorator.java b/components/camel-telemetry/src/main/java/org/apache/camel/telemetry/decorators/AwsKmsSpanDecorator.java new file mode 100644 index 000000000000..a08f7c375005 --- /dev/null +++ b/components/camel-telemetry/src/main/java/org/apache/camel/telemetry/decorators/AwsKmsSpanDecorator.java @@ -0,0 +1,66 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.camel.telemetry.decorators; + +import org.apache.camel.Endpoint; +import org.apache.camel.Exchange; +import org.apache.camel.telemetry.Span; + +public class AwsKmsSpanDecorator extends AbstractSpanDecorator { + + static final String KMS_OPERATION = "operation"; + static final String KMS_KEY_ARN = "keyArn"; + static final String KMS_KEY_STATE = "keyState"; + + /** + * Constants copied from {@link org.apache.camel.component.aws2.kms.KMS2Constants} + */ + static final String OPERATION = "CamelAwsKMSOperation"; + static final String KEY_ARN = "CamelAwsKMSKeyArn"; + static final String KEY_STATE = "CamelAwsKMSKeyState"; + + @Override + public String getComponent() { + return "aws2-kms"; + } + + @Override + public String getComponentClassName() { + return "org.apache.camel.component.aws2.kms.KMS2Component"; + } + + @Override + public void beforeTracingEvent(Span span, Exchange exchange, Endpoint endpoint) { + super.beforeTracingEvent(span, exchange, endpoint); + + String operation = exchange.getIn().getHeader(OPERATION, String.class); + if (operation != null) { + span.setTag(KMS_OPERATION, operation); + } + + String keyArn = exchange.getIn().getHeader(KEY_ARN, String.class); + if (keyArn != null) { + span.setTag(KMS_KEY_ARN, keyArn); + } + + String keyState = exchange.getIn().getHeader(KEY_STATE, String.class); + if (keyState != null) { + span.setTag(KMS_KEY_STATE, keyState); + } + } + +} diff --git a/components/camel-telemetry/src/main/java/org/apache/camel/telemetry/decorators/AwsMskSpanDecorator.java b/components/camel-telemetry/src/main/java/org/apache/camel/telemetry/decorators/AwsMskSpanDecorator.java new file mode 100644 index 000000000000..8cdb2826f05b --- /dev/null +++ b/components/camel-telemetry/src/main/java/org/apache/camel/telemetry/decorators/AwsMskSpanDecorator.java @@ -0,0 +1,73 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.camel.telemetry.decorators; + +import org.apache.camel.Endpoint; +import org.apache.camel.Exchange; +import org.apache.camel.telemetry.Span; + +public class AwsMskSpanDecorator extends AbstractSpanDecorator { + + static final String MSK_OPERATION = "operation"; + static final String MSK_CLUSTER_NAME = "clusterName"; + static final String MSK_CLUSTER_ARN = "clusterArn"; + static final String MSK_CLUSTER_STATE = "clusterState"; + + /** + * Constants copied from {@link org.apache.camel.component.aws2.msk.MSK2Constants} + */ + static final String OPERATION = "CamelAwsMSKOperation"; + static final String CLUSTER_NAME = "CamelAwsMSKClusterName"; + static final String CLUSTER_ARN = "CamelAwsMSKClusterArn"; + static final String CLUSTER_STATE = "CamelAwsMSKClusterState"; + + @Override + public String getComponent() { + return "aws2-msk"; + } + + @Override + public String getComponentClassName() { + return "org.apache.camel.component.aws2.msk.MSK2Component"; + } + + @Override + public void beforeTracingEvent(Span span, Exchange exchange, Endpoint endpoint) { + super.beforeTracingEvent(span, exchange, endpoint); + + String operation = exchange.getIn().getHeader(OPERATION, String.class); + if (operation != null) { + span.setTag(MSK_OPERATION, operation); + } + + String clusterName = exchange.getIn().getHeader(CLUSTER_NAME, String.class); + if (clusterName != null) { + span.setTag(MSK_CLUSTER_NAME, clusterName); + } + + String clusterArn = exchange.getIn().getHeader(CLUSTER_ARN, String.class); + if (clusterArn != null) { + span.setTag(MSK_CLUSTER_ARN, clusterArn); + } + + String clusterState = exchange.getIn().getHeader(CLUSTER_STATE, String.class); + if (clusterState != null) { + span.setTag(MSK_CLUSTER_STATE, clusterState); + } + } + +} diff --git a/components/camel-telemetry/src/main/java/org/apache/camel/telemetry/decorators/AwsRedshiftDataSpanDecorator.java b/components/camel-telemetry/src/main/java/org/apache/camel/telemetry/decorators/AwsRedshiftDataSpanDecorator.java new file mode 100644 index 000000000000..3ed55fb70edd --- /dev/null +++ b/components/camel-telemetry/src/main/java/org/apache/camel/telemetry/decorators/AwsRedshiftDataSpanDecorator.java @@ -0,0 +1,77 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.camel.telemetry.decorators; + +import org.apache.camel.Endpoint; +import org.apache.camel.Exchange; +import org.apache.camel.telemetry.Span; +import org.apache.camel.telemetry.TagConstants; + +public class AwsRedshiftDataSpanDecorator extends AbstractSpanDecorator { + + static final String REDSHIFTDATA_OPERATION = "operation"; + static final String REDSHIFTDATA_CLUSTER_IDENTIFIER = "clusterIdentifier"; + static final String REDSHIFTDATA_DATABASE = "database"; + static final String REDSHIFTDATA_STATEMENT_NAME = "statementName"; + + /** + * Constants copied from {@link org.apache.camel.component.aws2.redshift.data.RedshiftData2Constants} + */ + static final String OPERATION = "CamelAwsRedshiftDataOperation"; + static final String CLUSTER_IDENTIFIER = "CamelAwsRedshiftDataClusterIdentifier"; + static final String DATABASE = "CamelAwsRedshiftDataDatabase"; + static final String STATEMENT_NAME = "CamelAwsRedshiftDataStatementName"; + + @Override + public String getComponent() { + return "aws2-redshift-data"; + } + + @Override + public String getComponentClassName() { + return "org.apache.camel.component.aws2.redshift.data.RedshiftData2Component"; + } + + @Override + public void beforeTracingEvent(Span span, Exchange exchange, Endpoint endpoint) { + super.beforeTracingEvent(span, exchange, endpoint); + + span.setTag(TagConstants.DB_SYSTEM, "redshift"); + + String operation = exchange.getIn().getHeader(OPERATION, String.class); + if (operation != null) { + span.setTag(REDSHIFTDATA_OPERATION, operation); + } + + String clusterIdentifier = exchange.getIn().getHeader(CLUSTER_IDENTIFIER, String.class); + if (clusterIdentifier != null) { + span.setTag(REDSHIFTDATA_CLUSTER_IDENTIFIER, clusterIdentifier); + } + + String database = exchange.getIn().getHeader(DATABASE, String.class); + if (database != null) { + span.setTag(REDSHIFTDATA_DATABASE, database); + span.setTag(TagConstants.DB_NAME, database); + } + + String statementName = exchange.getIn().getHeader(STATEMENT_NAME, String.class); + if (statementName != null) { + span.setTag(REDSHIFTDATA_STATEMENT_NAME, statementName); + } + } + +} diff --git a/components/camel-telemetry/src/main/java/org/apache/camel/telemetry/decorators/AwsStepFunctionsSpanDecorator.java b/components/camel-telemetry/src/main/java/org/apache/camel/telemetry/decorators/AwsStepFunctionsSpanDecorator.java new file mode 100644 index 000000000000..1058d060736c --- /dev/null +++ b/components/camel-telemetry/src/main/java/org/apache/camel/telemetry/decorators/AwsStepFunctionsSpanDecorator.java @@ -0,0 +1,80 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.camel.telemetry.decorators; + +import org.apache.camel.Endpoint; +import org.apache.camel.Exchange; +import org.apache.camel.telemetry.Span; + +public class AwsStepFunctionsSpanDecorator extends AbstractSpanDecorator { + + static final String STEPFUNCTIONS_OPERATION = "operation"; + static final String STEPFUNCTIONS_STATE_MACHINE_NAME = "stateMachineName"; + static final String STEPFUNCTIONS_STATE_MACHINE_ARN = "stateMachineArn"; + static final String STEPFUNCTIONS_EXECUTION_ARN = "executionArn"; + static final String STEPFUNCTIONS_EXECUTION_NAME = "executionName"; + + /** + * Constants copied from {@link org.apache.camel.component.aws2.stepfunctions.StepFunctions2Constants} + */ + static final String OPERATION = "CamelAwsStepFunctionsOperation"; + static final String STATE_MACHINE_NAME = "CamelAwsStepFunctionsStateMachineName"; + static final String STATE_MACHINE_ARN = "CamelAwsStepFunctionsStateMachineArn"; + static final String EXECUTION_ARN = "CamelAwsStepFunctionsExecutionArn"; + static final String EXECUTION_NAME = "CamelAwsStepFunctionsExecutionName"; + + @Override + public String getComponent() { + return "aws2-step-functions"; + } + + @Override + public String getComponentClassName() { + return "org.apache.camel.component.aws2.stepfunctions.StepFunctions2Component"; + } + + @Override + public void beforeTracingEvent(Span span, Exchange exchange, Endpoint endpoint) { + super.beforeTracingEvent(span, exchange, endpoint); + + String operation = exchange.getIn().getHeader(OPERATION, String.class); + if (operation != null) { + span.setTag(STEPFUNCTIONS_OPERATION, operation); + } + + String stateMachineName = exchange.getIn().getHeader(STATE_MACHINE_NAME, String.class); + if (stateMachineName != null) { + span.setTag(STEPFUNCTIONS_STATE_MACHINE_NAME, stateMachineName); + } + + String stateMachineArn = exchange.getIn().getHeader(STATE_MACHINE_ARN, String.class); + if (stateMachineArn != null) { + span.setTag(STEPFUNCTIONS_STATE_MACHINE_ARN, stateMachineArn); + } + + String executionArn = exchange.getIn().getHeader(EXECUTION_ARN, String.class); + if (executionArn != null) { + span.setTag(STEPFUNCTIONS_EXECUTION_ARN, executionArn); + } + + String executionName = exchange.getIn().getHeader(EXECUTION_NAME, String.class); + if (executionName != null) { + span.setTag(STEPFUNCTIONS_EXECUTION_NAME, executionName); + } + } + +} diff --git a/components/camel-telemetry/src/main/java/org/apache/camel/telemetry/decorators/AwsTimestreamSpanDecorator.java b/components/camel-telemetry/src/main/java/org/apache/camel/telemetry/decorators/AwsTimestreamSpanDecorator.java new file mode 100644 index 000000000000..30ee7bb4f209 --- /dev/null +++ b/components/camel-telemetry/src/main/java/org/apache/camel/telemetry/decorators/AwsTimestreamSpanDecorator.java @@ -0,0 +1,70 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.camel.telemetry.decorators; + +import org.apache.camel.Endpoint; +import org.apache.camel.Exchange; +import org.apache.camel.telemetry.Span; +import org.apache.camel.telemetry.TagConstants; + +public class AwsTimestreamSpanDecorator extends AbstractSpanDecorator { + + static final String TIMESTREAM_OPERATION = "operation"; + static final String TIMESTREAM_DATABASE_NAME = "databaseName"; + static final String TIMESTREAM_TABLE_NAME = "tableName"; + + /** + * Constants copied from {@link org.apache.camel.component.aws2.timestream.Timestream2Constants} + */ + static final String OPERATION = "CamelAwsTimestreamOperation"; + static final String DATABASE_NAME = "CamelAwsTimestreamDatabaseName"; + static final String TABLE_NAME = "CamelAwsTimestreamTableName"; + + @Override + public String getComponent() { + return "aws2-timestream"; + } + + @Override + public String getComponentClassName() { + return "org.apache.camel.component.aws2.timestream.Timestream2Component"; + } + + @Override + public void beforeTracingEvent(Span span, Exchange exchange, Endpoint endpoint) { + super.beforeTracingEvent(span, exchange, endpoint); + + span.setTag(TagConstants.DB_SYSTEM, "timestream"); + + String operation = exchange.getIn().getHeader(OPERATION, String.class); + if (operation != null) { + span.setTag(TIMESTREAM_OPERATION, operation); + } + + String databaseName = exchange.getIn().getHeader(DATABASE_NAME, String.class); + if (databaseName != null) { + span.setTag(TIMESTREAM_DATABASE_NAME, databaseName); + span.setTag(TagConstants.DB_NAME, databaseName); + } + + String tableName = exchange.getIn().getHeader(TABLE_NAME, String.class); + if (tableName != null) { + span.setTag(TIMESTREAM_TABLE_NAME, tableName); + } + } + +} diff --git a/components/camel-telemetry/src/main/resources/META-INF/services/org.apache.camel.telemetry.SpanDecorator b/components/camel-telemetry/src/main/resources/META-INF/services/org.apache.camel.telemetry.SpanDecorator index 26073ccaa47a..c34a4b214104 100644 --- a/components/camel-telemetry/src/main/resources/META-INF/services/org.apache.camel.telemetry.SpanDecorator +++ b/components/camel-telemetry/src/main/resources/META-INF/services/org.apache.camel.telemetry.SpanDecorator @@ -19,18 +19,26 @@ org.apache.camel.telemetry.decorators.ActiveMQ6SpanDecorator org.apache.camel.telemetry.decorators.ActiveMQSpanDecorator org.apache.camel.telemetry.decorators.AhcSpanDecorator org.apache.camel.telemetry.decorators.AmqpSpanDecorator +org.apache.camel.telemetry.decorators.AwsAthenaSpanDecorator org.apache.camel.telemetry.decorators.AwsBedrockSpanDecorator +org.apache.camel.telemetry.decorators.AwsCloudtrailSpanDecorator +org.apache.camel.telemetry.decorators.AwsCwSpanDecorator org.apache.camel.telemetry.decorators.AwsDdbSpanDecorator org.apache.camel.telemetry.decorators.AwsDdbStreamSpanDecorator org.apache.camel.telemetry.decorators.AwsEventbridgeSpanDecorator org.apache.camel.telemetry.decorators.AwsKinesisFirehoseSpanDecorator org.apache.camel.telemetry.decorators.AwsKinesisSpanDecorator +org.apache.camel.telemetry.decorators.AwsKmsSpanDecorator org.apache.camel.telemetry.decorators.AwsLambdaSpanDecorator org.apache.camel.telemetry.decorators.AwsMqSpanDecorator +org.apache.camel.telemetry.decorators.AwsMskSpanDecorator +org.apache.camel.telemetry.decorators.AwsRedshiftDataSpanDecorator org.apache.camel.telemetry.decorators.AwsS3SpanDecorator org.apache.camel.telemetry.decorators.AwsSesSpanDecorator org.apache.camel.telemetry.decorators.AwsSnsSpanDecorator org.apache.camel.telemetry.decorators.AwsSqsSpanDecorator +org.apache.camel.telemetry.decorators.AwsStepFunctionsSpanDecorator +org.apache.camel.telemetry.decorators.AwsTimestreamSpanDecorator org.apache.camel.telemetry.decorators.AzureServiceBusSpanDecorator org.apache.camel.telemetry.decorators.CometdSpanDecorator org.apache.camel.telemetry.decorators.CometdsSpanDecorator diff --git a/components/camel-telemetry/src/test/java/org/apache/camel/telemetry/decorators/AwsAthenaSpanDecoratorTest.java b/components/camel-telemetry/src/test/java/org/apache/camel/telemetry/decorators/AwsAthenaSpanDecoratorTest.java new file mode 100644 index 000000000000..a05b3de296f1 --- /dev/null +++ b/components/camel-telemetry/src/test/java/org/apache/camel/telemetry/decorators/AwsAthenaSpanDecoratorTest.java @@ -0,0 +1,67 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.camel.telemetry.decorators; + +import org.apache.camel.Endpoint; +import org.apache.camel.Exchange; +import org.apache.camel.Message; +import org.apache.camel.telemetry.TagConstants; +import org.apache.camel.telemetry.mock.MockSpanAdapter; +import org.junit.jupiter.api.Test; +import org.mockito.Mockito; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class AwsAthenaSpanDecoratorTest { + + @Test + public void testPre() { + String operation = "startQueryExecution"; + String database = "myDatabase"; + String queryExecutionId = "abcd-1234"; + String workGroup = "primary"; + String queryExecutionState = "SUCCEEDED"; + + Endpoint endpoint = Mockito.mock(Endpoint.class); + Exchange exchange = Mockito.mock(Exchange.class); + Message message = Mockito.mock(Message.class); + + Mockito.when(endpoint.getEndpointUri()).thenReturn("aws2-athena:default"); + Mockito.when(exchange.getIn()).thenReturn(message); + Mockito.when(exchange.getExchangeId()).thenReturn("exchange-1"); + Mockito.when(message.getHeader(AwsAthenaSpanDecorator.OPERATION)).thenReturn(operation); + Mockito.when(message.getHeader(AwsAthenaSpanDecorator.DATABASE, String.class)).thenReturn(database); + Mockito.when(message.getHeader(AwsAthenaSpanDecorator.QUERY_EXECUTION_ID, String.class)).thenReturn(queryExecutionId); + Mockito.when(message.getHeader(AwsAthenaSpanDecorator.WORK_GROUP, String.class)).thenReturn(workGroup); + Mockito.when(message.getHeader(AwsAthenaSpanDecorator.QUERY_EXECUTION_STATE)).thenReturn(queryExecutionState); + + AbstractSpanDecorator decorator = new AwsAthenaSpanDecorator(); + + MockSpanAdapter span = new MockSpanAdapter(); + + decorator.beforeTracingEvent(span, exchange, endpoint); + + assertEquals("athena", span.tags().get(TagConstants.DB_SYSTEM)); + assertEquals(operation, span.tags().get(AwsAthenaSpanDecorator.ATHENA_OPERATION)); + assertEquals(database, span.tags().get(AwsAthenaSpanDecorator.ATHENA_DATABASE)); + assertEquals(database, span.tags().get(TagConstants.DB_NAME)); + assertEquals(queryExecutionId, span.tags().get(AwsAthenaSpanDecorator.ATHENA_QUERY_EXECUTION_ID)); + assertEquals(workGroup, span.tags().get(AwsAthenaSpanDecorator.ATHENA_WORK_GROUP)); + assertEquals(queryExecutionState, span.tags().get(AwsAthenaSpanDecorator.ATHENA_QUERY_EXECUTION_STATE)); + } + +} diff --git a/components/camel-telemetry/src/test/java/org/apache/camel/telemetry/decorators/AwsCloudtrailSpanDecoratorTest.java b/components/camel-telemetry/src/test/java/org/apache/camel/telemetry/decorators/AwsCloudtrailSpanDecoratorTest.java new file mode 100644 index 000000000000..212df192e016 --- /dev/null +++ b/components/camel-telemetry/src/test/java/org/apache/camel/telemetry/decorators/AwsCloudtrailSpanDecoratorTest.java @@ -0,0 +1,68 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.camel.telemetry.decorators; + +import org.apache.camel.Endpoint; +import org.apache.camel.Exchange; +import org.apache.camel.Message; +import org.apache.camel.telemetry.mock.MockSpanAdapter; +import org.junit.jupiter.api.Test; +import org.mockito.Mockito; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class AwsCloudtrailSpanDecoratorTest { + + @Test + public void testGetMessageId() { + String eventId = "abcd-1234"; + Exchange exchange = Mockito.mock(Exchange.class); + Message message = Mockito.mock(Message.class); + + Mockito.when(exchange.getIn()).thenReturn(message); + Mockito.when(message.getHeader(AwsCloudtrailSpanDecorator.EVENT_ID, String.class)).thenReturn(eventId); + + AbstractMessagingSpanDecorator decorator = new AwsCloudtrailSpanDecorator(); + + assertEquals(eventId, decorator.getMessageId(exchange)); + } + + @Test + public void testPre() { + String eventName = "ConsoleLogin"; + String eventSource = "signin.amazonaws.com"; + + Endpoint endpoint = Mockito.mock(Endpoint.class); + Exchange exchange = Mockito.mock(Exchange.class); + Message message = Mockito.mock(Message.class); + + Mockito.when(endpoint.getEndpointUri()).thenReturn("aws-cloudtrail:default"); + Mockito.when(exchange.getIn()).thenReturn(message); + Mockito.when(message.getHeader(AwsCloudtrailSpanDecorator.EVENT_NAME, String.class)).thenReturn(eventName); + Mockito.when(message.getHeader(AwsCloudtrailSpanDecorator.EVENT_SOURCE, String.class)).thenReturn(eventSource); + + AbstractMessagingSpanDecorator decorator = new AwsCloudtrailSpanDecorator(); + + MockSpanAdapter span = new MockSpanAdapter(); + + decorator.beforeTracingEvent(span, exchange, endpoint); + + assertEquals(eventName, span.tags().get(AwsCloudtrailSpanDecorator.CLOUDTRAIL_EVENT_NAME)); + assertEquals(eventSource, span.tags().get(AwsCloudtrailSpanDecorator.CLOUDTRAIL_EVENT_SOURCE)); + } + +} diff --git a/components/camel-telemetry/src/test/java/org/apache/camel/telemetry/decorators/AwsCwSpanDecoratorTest.java b/components/camel-telemetry/src/test/java/org/apache/camel/telemetry/decorators/AwsCwSpanDecoratorTest.java new file mode 100644 index 000000000000..03c3bbdf6e7b --- /dev/null +++ b/components/camel-telemetry/src/test/java/org/apache/camel/telemetry/decorators/AwsCwSpanDecoratorTest.java @@ -0,0 +1,64 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.camel.telemetry.decorators; + +import org.apache.camel.Endpoint; +import org.apache.camel.Exchange; +import org.apache.camel.Message; +import org.apache.camel.telemetry.mock.MockSpanAdapter; +import org.junit.jupiter.api.Test; +import org.mockito.Mockito; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class AwsCwSpanDecoratorTest { + + @Test + public void testPre() { + String operation = "putMetricData"; + String metricNamespace = "MyApp"; + String metricName = "RequestCount"; + String alarmName = "HighRequestCount"; + String alarmState = "ALARM"; + + Endpoint endpoint = Mockito.mock(Endpoint.class); + Exchange exchange = Mockito.mock(Exchange.class); + Message message = Mockito.mock(Message.class); + + Mockito.when(endpoint.getEndpointUri()).thenReturn("aws2-cw:MyApp"); + Mockito.when(exchange.getIn()).thenReturn(message); + Mockito.when(exchange.getExchangeId()).thenReturn("exchange-1"); + Mockito.when(message.getHeader(AwsCwSpanDecorator.OPERATION, String.class)).thenReturn(operation); + Mockito.when(message.getHeader(AwsCwSpanDecorator.METRIC_NAMESPACE, String.class)).thenReturn(metricNamespace); + Mockito.when(message.getHeader(AwsCwSpanDecorator.METRIC_NAME, String.class)).thenReturn(metricName); + Mockito.when(message.getHeader(AwsCwSpanDecorator.ALARM_NAME, String.class)).thenReturn(alarmName); + Mockito.when(message.getHeader(AwsCwSpanDecorator.ALARM_STATE, String.class)).thenReturn(alarmState); + + AbstractSpanDecorator decorator = new AwsCwSpanDecorator(); + + MockSpanAdapter span = new MockSpanAdapter(); + + decorator.beforeTracingEvent(span, exchange, endpoint); + + assertEquals(operation, span.tags().get(AwsCwSpanDecorator.CW_OPERATION)); + assertEquals(metricNamespace, span.tags().get(AwsCwSpanDecorator.CW_METRIC_NAMESPACE)); + assertEquals(metricName, span.tags().get(AwsCwSpanDecorator.CW_METRIC_NAME)); + assertEquals(alarmName, span.tags().get(AwsCwSpanDecorator.CW_ALARM_NAME)); + assertEquals(alarmState, span.tags().get(AwsCwSpanDecorator.CW_ALARM_STATE)); + } + +} diff --git a/components/camel-telemetry/src/test/java/org/apache/camel/telemetry/decorators/AwsKmsSpanDecoratorTest.java b/components/camel-telemetry/src/test/java/org/apache/camel/telemetry/decorators/AwsKmsSpanDecoratorTest.java new file mode 100644 index 000000000000..3985ec54afbf --- /dev/null +++ b/components/camel-telemetry/src/test/java/org/apache/camel/telemetry/decorators/AwsKmsSpanDecoratorTest.java @@ -0,0 +1,58 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.camel.telemetry.decorators; + +import org.apache.camel.Endpoint; +import org.apache.camel.Exchange; +import org.apache.camel.Message; +import org.apache.camel.telemetry.mock.MockSpanAdapter; +import org.junit.jupiter.api.Test; +import org.mockito.Mockito; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class AwsKmsSpanDecoratorTest { + + @Test + public void testPre() { + String operation = "createKey"; + String keyArn = "arn:aws:kms:us-east-1:123456789012:key/1234abcd-12ab-34cd-56ef-1234567890ab"; + String keyState = "Enabled"; + + Endpoint endpoint = Mockito.mock(Endpoint.class); + Exchange exchange = Mockito.mock(Exchange.class); + Message message = Mockito.mock(Message.class); + + Mockito.when(endpoint.getEndpointUri()).thenReturn("aws2-kms:default"); + Mockito.when(exchange.getIn()).thenReturn(message); + Mockito.when(exchange.getExchangeId()).thenReturn("exchange-1"); + Mockito.when(message.getHeader(AwsKmsSpanDecorator.OPERATION, String.class)).thenReturn(operation); + Mockito.when(message.getHeader(AwsKmsSpanDecorator.KEY_ARN, String.class)).thenReturn(keyArn); + Mockito.when(message.getHeader(AwsKmsSpanDecorator.KEY_STATE, String.class)).thenReturn(keyState); + + AbstractSpanDecorator decorator = new AwsKmsSpanDecorator(); + + MockSpanAdapter span = new MockSpanAdapter(); + + decorator.beforeTracingEvent(span, exchange, endpoint); + + assertEquals(operation, span.tags().get(AwsKmsSpanDecorator.KMS_OPERATION)); + assertEquals(keyArn, span.tags().get(AwsKmsSpanDecorator.KMS_KEY_ARN)); + assertEquals(keyState, span.tags().get(AwsKmsSpanDecorator.KMS_KEY_STATE)); + } + +} diff --git a/components/camel-telemetry/src/test/java/org/apache/camel/telemetry/decorators/AwsMskSpanDecoratorTest.java b/components/camel-telemetry/src/test/java/org/apache/camel/telemetry/decorators/AwsMskSpanDecoratorTest.java new file mode 100644 index 000000000000..e7348b1b0b05 --- /dev/null +++ b/components/camel-telemetry/src/test/java/org/apache/camel/telemetry/decorators/AwsMskSpanDecoratorTest.java @@ -0,0 +1,61 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.camel.telemetry.decorators; + +import org.apache.camel.Endpoint; +import org.apache.camel.Exchange; +import org.apache.camel.Message; +import org.apache.camel.telemetry.mock.MockSpanAdapter; +import org.junit.jupiter.api.Test; +import org.mockito.Mockito; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class AwsMskSpanDecoratorTest { + + @Test + public void testPre() { + String operation = "createCluster"; + String clusterName = "myCluster"; + String clusterArn = "arn:aws:kafka:us-east-1:123456789012:cluster/myCluster/abcd"; + String clusterState = "ACTIVE"; + + Endpoint endpoint = Mockito.mock(Endpoint.class); + Exchange exchange = Mockito.mock(Exchange.class); + Message message = Mockito.mock(Message.class); + + Mockito.when(endpoint.getEndpointUri()).thenReturn("aws2-msk:default"); + Mockito.when(exchange.getIn()).thenReturn(message); + Mockito.when(exchange.getExchangeId()).thenReturn("exchange-1"); + Mockito.when(message.getHeader(AwsMskSpanDecorator.OPERATION, String.class)).thenReturn(operation); + Mockito.when(message.getHeader(AwsMskSpanDecorator.CLUSTER_NAME, String.class)).thenReturn(clusterName); + Mockito.when(message.getHeader(AwsMskSpanDecorator.CLUSTER_ARN, String.class)).thenReturn(clusterArn); + Mockito.when(message.getHeader(AwsMskSpanDecorator.CLUSTER_STATE, String.class)).thenReturn(clusterState); + + AbstractSpanDecorator decorator = new AwsMskSpanDecorator(); + + MockSpanAdapter span = new MockSpanAdapter(); + + decorator.beforeTracingEvent(span, exchange, endpoint); + + assertEquals(operation, span.tags().get(AwsMskSpanDecorator.MSK_OPERATION)); + assertEquals(clusterName, span.tags().get(AwsMskSpanDecorator.MSK_CLUSTER_NAME)); + assertEquals(clusterArn, span.tags().get(AwsMskSpanDecorator.MSK_CLUSTER_ARN)); + assertEquals(clusterState, span.tags().get(AwsMskSpanDecorator.MSK_CLUSTER_STATE)); + } + +} diff --git a/components/camel-telemetry/src/test/java/org/apache/camel/telemetry/decorators/AwsRedshiftDataSpanDecoratorTest.java b/components/camel-telemetry/src/test/java/org/apache/camel/telemetry/decorators/AwsRedshiftDataSpanDecoratorTest.java new file mode 100644 index 000000000000..232abd451009 --- /dev/null +++ b/components/camel-telemetry/src/test/java/org/apache/camel/telemetry/decorators/AwsRedshiftDataSpanDecoratorTest.java @@ -0,0 +1,65 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.camel.telemetry.decorators; + +import org.apache.camel.Endpoint; +import org.apache.camel.Exchange; +import org.apache.camel.Message; +import org.apache.camel.telemetry.TagConstants; +import org.apache.camel.telemetry.mock.MockSpanAdapter; +import org.junit.jupiter.api.Test; +import org.mockito.Mockito; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class AwsRedshiftDataSpanDecoratorTest { + + @Test + public void testPre() { + String operation = "executeStatement"; + String clusterIdentifier = "myCluster"; + String database = "myDatabase"; + String statementName = "myStatement"; + + Endpoint endpoint = Mockito.mock(Endpoint.class); + Exchange exchange = Mockito.mock(Exchange.class); + Message message = Mockito.mock(Message.class); + + Mockito.when(endpoint.getEndpointUri()).thenReturn("aws2-redshift-data:default"); + Mockito.when(exchange.getIn()).thenReturn(message); + Mockito.when(exchange.getExchangeId()).thenReturn("exchange-1"); + Mockito.when(message.getHeader(AwsRedshiftDataSpanDecorator.OPERATION, String.class)).thenReturn(operation); + Mockito.when(message.getHeader(AwsRedshiftDataSpanDecorator.CLUSTER_IDENTIFIER, String.class)) + .thenReturn(clusterIdentifier); + Mockito.when(message.getHeader(AwsRedshiftDataSpanDecorator.DATABASE, String.class)).thenReturn(database); + Mockito.when(message.getHeader(AwsRedshiftDataSpanDecorator.STATEMENT_NAME, String.class)).thenReturn(statementName); + + AbstractSpanDecorator decorator = new AwsRedshiftDataSpanDecorator(); + + MockSpanAdapter span = new MockSpanAdapter(); + + decorator.beforeTracingEvent(span, exchange, endpoint); + + assertEquals("redshift", span.tags().get(TagConstants.DB_SYSTEM)); + assertEquals(operation, span.tags().get(AwsRedshiftDataSpanDecorator.REDSHIFTDATA_OPERATION)); + assertEquals(clusterIdentifier, span.tags().get(AwsRedshiftDataSpanDecorator.REDSHIFTDATA_CLUSTER_IDENTIFIER)); + assertEquals(database, span.tags().get(AwsRedshiftDataSpanDecorator.REDSHIFTDATA_DATABASE)); + assertEquals(database, span.tags().get(TagConstants.DB_NAME)); + assertEquals(statementName, span.tags().get(AwsRedshiftDataSpanDecorator.REDSHIFTDATA_STATEMENT_NAME)); + } + +} diff --git a/components/camel-telemetry/src/test/java/org/apache/camel/telemetry/decorators/AwsStepFunctionsSpanDecoratorTest.java b/components/camel-telemetry/src/test/java/org/apache/camel/telemetry/decorators/AwsStepFunctionsSpanDecoratorTest.java new file mode 100644 index 000000000000..b20372f377e8 --- /dev/null +++ b/components/camel-telemetry/src/test/java/org/apache/camel/telemetry/decorators/AwsStepFunctionsSpanDecoratorTest.java @@ -0,0 +1,66 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.camel.telemetry.decorators; + +import org.apache.camel.Endpoint; +import org.apache.camel.Exchange; +import org.apache.camel.Message; +import org.apache.camel.telemetry.mock.MockSpanAdapter; +import org.junit.jupiter.api.Test; +import org.mockito.Mockito; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class AwsStepFunctionsSpanDecoratorTest { + + @Test + public void testPre() { + String operation = "startExecution"; + String stateMachineName = "myStateMachine"; + String stateMachineArn = "arn:aws:states:us-east-1:123456789012:stateMachine:myStateMachine"; + String executionArn = "arn:aws:states:us-east-1:123456789012:execution:myStateMachine:abcd"; + String executionName = "myExecution"; + + Endpoint endpoint = Mockito.mock(Endpoint.class); + Exchange exchange = Mockito.mock(Exchange.class); + Message message = Mockito.mock(Message.class); + + Mockito.when(endpoint.getEndpointUri()).thenReturn("aws2-step-functions:default"); + Mockito.when(exchange.getIn()).thenReturn(message); + Mockito.when(exchange.getExchangeId()).thenReturn("exchange-1"); + Mockito.when(message.getHeader(AwsStepFunctionsSpanDecorator.OPERATION, String.class)).thenReturn(operation); + Mockito.when(message.getHeader(AwsStepFunctionsSpanDecorator.STATE_MACHINE_NAME, String.class)) + .thenReturn(stateMachineName); + Mockito.when(message.getHeader(AwsStepFunctionsSpanDecorator.STATE_MACHINE_ARN, String.class)) + .thenReturn(stateMachineArn); + Mockito.when(message.getHeader(AwsStepFunctionsSpanDecorator.EXECUTION_ARN, String.class)).thenReturn(executionArn); + Mockito.when(message.getHeader(AwsStepFunctionsSpanDecorator.EXECUTION_NAME, String.class)).thenReturn(executionName); + + AbstractSpanDecorator decorator = new AwsStepFunctionsSpanDecorator(); + + MockSpanAdapter span = new MockSpanAdapter(); + + decorator.beforeTracingEvent(span, exchange, endpoint); + + assertEquals(operation, span.tags().get(AwsStepFunctionsSpanDecorator.STEPFUNCTIONS_OPERATION)); + assertEquals(stateMachineName, span.tags().get(AwsStepFunctionsSpanDecorator.STEPFUNCTIONS_STATE_MACHINE_NAME)); + assertEquals(stateMachineArn, span.tags().get(AwsStepFunctionsSpanDecorator.STEPFUNCTIONS_STATE_MACHINE_ARN)); + assertEquals(executionArn, span.tags().get(AwsStepFunctionsSpanDecorator.STEPFUNCTIONS_EXECUTION_ARN)); + assertEquals(executionName, span.tags().get(AwsStepFunctionsSpanDecorator.STEPFUNCTIONS_EXECUTION_NAME)); + } + +} diff --git a/components/camel-telemetry/src/test/java/org/apache/camel/telemetry/decorators/AwsTimestreamSpanDecoratorTest.java b/components/camel-telemetry/src/test/java/org/apache/camel/telemetry/decorators/AwsTimestreamSpanDecoratorTest.java new file mode 100644 index 000000000000..eb6c9e2b85d0 --- /dev/null +++ b/components/camel-telemetry/src/test/java/org/apache/camel/telemetry/decorators/AwsTimestreamSpanDecoratorTest.java @@ -0,0 +1,61 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.camel.telemetry.decorators; + +import org.apache.camel.Endpoint; +import org.apache.camel.Exchange; +import org.apache.camel.Message; +import org.apache.camel.telemetry.TagConstants; +import org.apache.camel.telemetry.mock.MockSpanAdapter; +import org.junit.jupiter.api.Test; +import org.mockito.Mockito; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class AwsTimestreamSpanDecoratorTest { + + @Test + public void testPre() { + String operation = "writeRecords"; + String databaseName = "myDatabase"; + String tableName = "myTable"; + + Endpoint endpoint = Mockito.mock(Endpoint.class); + Exchange exchange = Mockito.mock(Exchange.class); + Message message = Mockito.mock(Message.class); + + Mockito.when(endpoint.getEndpointUri()).thenReturn("aws2-timestream:write"); + Mockito.when(exchange.getIn()).thenReturn(message); + Mockito.when(exchange.getExchangeId()).thenReturn("exchange-1"); + Mockito.when(message.getHeader(AwsTimestreamSpanDecorator.OPERATION, String.class)).thenReturn(operation); + Mockito.when(message.getHeader(AwsTimestreamSpanDecorator.DATABASE_NAME, String.class)).thenReturn(databaseName); + Mockito.when(message.getHeader(AwsTimestreamSpanDecorator.TABLE_NAME, String.class)).thenReturn(tableName); + + AbstractSpanDecorator decorator = new AwsTimestreamSpanDecorator(); + + MockSpanAdapter span = new MockSpanAdapter(); + + decorator.beforeTracingEvent(span, exchange, endpoint); + + assertEquals("timestream", span.tags().get(TagConstants.DB_SYSTEM)); + assertEquals(operation, span.tags().get(AwsTimestreamSpanDecorator.TIMESTREAM_OPERATION)); + assertEquals(databaseName, span.tags().get(AwsTimestreamSpanDecorator.TIMESTREAM_DATABASE_NAME)); + assertEquals(databaseName, span.tags().get(TagConstants.DB_NAME)); + assertEquals(tableName, span.tags().get(AwsTimestreamSpanDecorator.TIMESTREAM_TABLE_NAME)); + } + +}
