|
19 | 19 | import static io.opentelemetry.semconv.SemanticAttributes.MessagingOperationValues.PROCESS;
|
20 | 20 | import static io.opentelemetry.semconv.SemanticAttributes.MessagingOperationValues.RECEIVE;
|
21 | 21 | import static org.assertj.core.api.Assertions.assertThat;
|
| 22 | +import static org.mockito.Answers.CALLS_REAL_METHODS; |
22 | 23 | import static org.mockito.Mockito.mock;
|
| 24 | +import static org.mockito.Mockito.mockStatic; |
23 | 25 | import static org.mockito.Mockito.when;
|
| 26 | +import static org.mockito.Mockito.withSettings; |
| 27 | +import static software.amazon.opentelemetry.javaagent.providers.AwsAttributeKeys.AWS_LAMBDA_LOCAL_OPERATION_OVERRIDE; |
24 | 28 | import static software.amazon.opentelemetry.javaagent.providers.AwsAttributeKeys.AWS_LOCAL_OPERATION;
|
25 | 29 | import static software.amazon.opentelemetry.javaagent.providers.AwsSpanProcessingUtil.MAX_KEYWORD_LENGTH;
|
26 | 30 | import static software.amazon.opentelemetry.javaagent.providers.AwsSpanProcessingUtil.getDialectKeywords;
|
|
33 | 37 | import java.util.List;
|
34 | 38 | import org.junit.jupiter.api.BeforeEach;
|
35 | 39 | import org.junit.jupiter.api.Test;
|
| 40 | +import org.mockito.MockedStatic; |
36 | 41 |
|
37 | 42 | public class AwsSpanProcessingUtilTest {
|
38 | 43 | private static final String DEFAULT_PATH_VALUE = "/";
|
@@ -120,6 +125,49 @@ public void testGetIngressOperationInvalidNameAndValidTargetAndMethod() {
|
120 | 125 | assertThat(actualOperation).isEqualTo(validMethod + " " + validTarget);
|
121 | 126 | }
|
122 | 127 |
|
| 128 | + @Test |
| 129 | + public void testGetIngressOperationLambdaOverride() { |
| 130 | + try (MockedStatic<AwsApplicationSignalsCustomizerProvider> providerStatic = |
| 131 | + mockStatic( |
| 132 | + AwsApplicationSignalsCustomizerProvider.class, |
| 133 | + withSettings().defaultAnswer(CALLS_REAL_METHODS))) { |
| 134 | + // Force Lambda environment branch |
| 135 | + providerStatic |
| 136 | + .when(AwsApplicationSignalsCustomizerProvider::isLambdaEnvironment) |
| 137 | + .thenReturn(true); |
| 138 | + // Simulate an override attribute on the span |
| 139 | + when(attributesMock.get(AWS_LAMBDA_LOCAL_OPERATION_OVERRIDE)).thenReturn("MyOverrideOp"); |
| 140 | + |
| 141 | + String actualOperation = AwsSpanProcessingUtil.getIngressOperation(spanDataMock); |
| 142 | + assertThat(actualOperation).isEqualTo("MyOverrideOp"); |
| 143 | + } |
| 144 | + } |
| 145 | + |
| 146 | + @Test |
| 147 | + public void testGetIngressOperationLambdaDefault() throws Exception { |
| 148 | + try ( |
| 149 | + // Mock the AWS environment check |
| 150 | + MockedStatic<AwsApplicationSignalsCustomizerProvider> providerStatic = |
| 151 | + mockStatic( |
| 152 | + AwsApplicationSignalsCustomizerProvider.class, |
| 153 | + withSettings().defaultAnswer(CALLS_REAL_METHODS)); |
| 154 | + // Mock only getFunctionNameFromEnv, leave all other util logic untouched |
| 155 | + MockedStatic<AwsSpanProcessingUtil> utilStatic = |
| 156 | + mockStatic( |
| 157 | + AwsSpanProcessingUtil.class, withSettings().defaultAnswer(CALLS_REAL_METHODS))) { |
| 158 | + // force lambda branch and no override attribute |
| 159 | + providerStatic |
| 160 | + .when(AwsApplicationSignalsCustomizerProvider::isLambdaEnvironment) |
| 161 | + .thenReturn(true); |
| 162 | + when(attributesMock.get(AWS_LAMBDA_LOCAL_OPERATION_OVERRIDE)).thenReturn(null); |
| 163 | + // Provide a deterministic function name |
| 164 | + utilStatic.when(AwsSpanProcessingUtil::getFunctionNameFromEnv).thenReturn("MockFunction"); |
| 165 | + |
| 166 | + String actual = AwsSpanProcessingUtil.getIngressOperation(spanDataMock); |
| 167 | + assertThat(actual).isEqualTo("MockFunction/FunctionHandler"); |
| 168 | + } |
| 169 | + } |
| 170 | + |
123 | 171 | @Test
|
124 | 172 | public void testGetEgressOperationUseInternalOperation() {
|
125 | 173 | String invalidName = null;
|
|
0 commit comments