Commit 985be39
authored
Add Service and Environment dimensions to EMF metrics when Application Signals is enabled (#548)
## Summary
When both OTEL_AWS_APPLICATION_SIGNALS_ENABLED and
OTEL_AWS_APPLICATION_SIGNALS_EMF_EXPORT_ENABLED are true, inject
"Service" and "Environment" dimensions into EMF metrics.
- Service: extracted from resource via get_service_attribute(), falls
back to "UnknownService"
- Environment: extracted from deployment.environment resource attribute,
falls back to "lambda:default"
- Case-insensitive check prevents overwriting user-set dimensions
- Lambda wrapper sets
OTEL_AWS_APPLICATION_SIGNALS_EMF_EXPORT_ENABLED=true
by default
## Test plan
- [x] Unit tests added for Lambda dimension injection in
`test_base_emf_exporter.py`
- [x] Unit tests added for `is_lambda` parameter in
`test_console_emf_exporter.py`
- [x] Existing configurator tests updated in
`test_aws_opentelementry_configurator.py`
- [x] Integration tested on Lambda
- [x] Verified EMF output contains Service and Environment dimensions
- [x] Verified CloudWatch metrics have correct dimensions
## Testing
### Lambda Code
```
import json
import os
import boto3
import requests
from opentelemetry import metrics, trace
# Get tracer and meter
tracer = trace.get_tracer(__name__)
meter = metrics.get_meter(__name__)
# Create a counter for custom metrics
request_counter = meter.create_counter(
"test.requests",
unit="1",
description="Test request counter"
)
# Initialize S3 client (outside handler for connection reuse)
s3_client = boto3.client("s3")
def lambda_handler(event, context):
# 1. Custom span with HTTP call - generates Application Signals service metrics
with tracer.start_as_current_span("my-custom-span") as span:
span.set_attribute("key1", "value1")
span.add_event("custom-event", {"detail": "something happened"})
requests.get("https://aws.amazon.com/")
# 2. AWS SDK call - generates Application Signals dependency metrics
s3_client.list_buckets()
# 3. Custom metric emission - will be converted to EMF
request_counter.add(1, {"operation": "test"})
return {
"statusCode": 200,
"body": json.dumps({
"message": "Metrics and traces emitted",
"function_name": os.environ.get("AWS_LAMBDA_FUNCTION_NAME"),
"trace_id": os.environ.get("_X_AMZN_TRACE_ID")
})
}
```
### CW Metrics
<img width="912" height="343" alt="image"
src="https://github.com/user-attachments/assets/e25ac297-3d7a-4076-b73c-0a16d0b62d0c"
/>
### Application Signals Related Metrics
<img width="2560" height="1440" alt="image"
src="https://github.com/user-attachments/assets/5b1e5d38-a9f3-406f-9b11-cb155e2c900d"
/>
🤖 Generated with [Claude Code](https://claude.com/claude-code)File tree
5 files changed
+242
-3
lines changed- aws-opentelemetry-distro
- src/amazon/opentelemetry/distro/exporter/aws/metrics
- tests/amazon/opentelemetry/distro
- exporter/aws/metrics
- lambda-layer/src
5 files changed
+242
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
| 15 | + | |
14 | 16 | | |
15 | 17 | | |
16 | 18 | | |
| |||
aws-opentelemetry-distro/src/amazon/opentelemetry/distro/exporter/aws/metrics/base_emf_exporter.py
Lines changed: 61 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
| 15 | + | |
14 | 16 | | |
15 | 17 | | |
16 | 18 | | |
| |||
28 | 30 | | |
29 | 31 | | |
30 | 32 | | |
| 33 | + | |
31 | 34 | | |
32 | 35 | | |
33 | 36 | | |
34 | 37 | | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
35 | 46 | | |
36 | 47 | | |
37 | 48 | | |
| |||
184 | 195 | | |
185 | 196 | | |
186 | 197 | | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
187 | 245 | | |
188 | 246 | | |
189 | 247 | | |
| |||
493 | 551 | | |
494 | 552 | | |
495 | 553 | | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
496 | 557 | | |
497 | 558 | | |
498 | 559 | | |
| |||
Lines changed: 169 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
4 | 5 | | |
5 | | - | |
| 6 | + | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
| |||
286 | 287 | | |
287 | 288 | | |
288 | 289 | | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
289 | 457 | | |
290 | 458 | | |
291 | 459 | | |
aws-opentelemetry-distro/tests/amazon/opentelemetry/distro/test_aws_opentelementry_configurator.py
Lines changed: 6 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1327 | 1327 | | |
1328 | 1328 | | |
1329 | 1329 | | |
1330 | | - | |
| 1330 | + | |
| 1331 | + | |
| 1332 | + | |
1331 | 1333 | | |
1332 | 1334 | | |
1333 | 1335 | | |
| |||
1474 | 1476 | | |
1475 | 1477 | | |
1476 | 1478 | | |
1477 | | - | |
| 1479 | + | |
| 1480 | + | |
| 1481 | + | |
1478 | 1482 | | |
1479 | 1483 | | |
1480 | 1484 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
115 | 115 | | |
116 | 116 | | |
117 | 117 | | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
118 | 122 | | |
119 | 123 | | |
120 | 124 | | |
| |||
0 commit comments