Skip to content

Conversation

@imanshafiei540
Copy link
Contributor

@imanshafiei540 imanshafiei540 commented Mar 31, 2025

Context

Add support for Python3.13

Testing

  • I ran this command bash run.sh -n test-otel-313 -b true and walked through the zip file.
  • I can do further testing by spinning up a Lambda instance (Please let me know)

The reason I created this PR: aws-observability/aws-otel-lambda#1080

closes #1755

@imanshafiei540 imanshafiei540 requested a review from a team as a code owner March 31, 2025 22:48
@serkan-ozal
Copy link
Contributor

@imanshafiei540 Thanks for your contribution. Have you tested OTEL Python layer with Python version 3.13 on real AWS Lambda environment?

@imanshafiei540
Copy link
Contributor Author

Thanks, and sorry for the delayed response.

Here are the details of how I've tested the local build with an actual Lambda instance:

Lambda configuration:

Runtime/Architecture: Python3.13 (x86_64)

image

I've compressed the contents in .aws-sam/build/OTelLayer/python. The final zip file that I uploaded to aws has the correct structure like python/<packages>.

Attached the layer to the Lambda instance.

And just ran the Lambda with this:

import json
import time
import logging

from opentelemetry import trace, metrics
from opentelemetry.sdk.resources import Resource
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import ConsoleSpanExporter, SimpleSpanProcessor
from opentelemetry.sdk.metrics import MeterProvider
from opentelemetry.sdk.metrics.export import (
    ConsoleMetricExporter,
    PeriodicExportingMetricReader,
)

trace.set_tracer_provider(
    TracerProvider(resource=Resource.create({"service.name": "otel-py313-test"}))
)
trace.get_tracer_provider().add_span_processor(
    SimpleSpanProcessor(ConsoleSpanExporter())
)

metrics.set_meter_provider(
    MeterProvider(
        resource=Resource.create({"service.name": "otel-py313-test"}),
        metric_readers=[PeriodicExportingMetricReader(ConsoleMetricExporter())],
    )
)

logger = logging.getLogger("otel-py313-logger")
logger.setLevel(logging.INFO)

tracer = trace.get_tracer(__name__)
meter = metrics.get_meter(__name__)
counter = meter.create_counter("lambda_invocation_count")


def lambda_handler(event, context):
    counter.add(1, {"function": "lambda_handler"})
    logger.info("Lambda invoked")

    with tracer.start_as_current_span("test-span") as span:
        span.set_attribute("custom.attribute", "test-otel")
        time.sleep(0.1)

    return {"statusCode": 200, "body": "OK"}

Here is the output:

Status: Succeeded
Test Event Name: TestEvent

Response:
{
  "statusCode": 200,
  "body": "OK"
}

Function Logs:
START RequestId: 0dd2717b-621c-4bd1-ac58-2013e88a33e0 Version: $LATEST
{
"resource_metrics": [
{
"resource": {
"attributes": {
"telemetry.sdk.language": "python",
"telemetry.sdk.name": "opentelemetry",
"telemetry.sdk.version": "1.30.0",
"service.name": "otel-py313-test"
},
"schema_url": ""
},
"scope_metrics": [
{
"scope": {
"name": "lambda_function",
"version": "",
"schema_url": "",
"attributes": null
},
"metrics": [
{
"name": "lambda_invocation_count",
"description": "",
"unit": "",
"data": {
"data_points": [
{
"attributes": {
"function": "lambda_handler"
},
"start_time_unix_nano": 1743544670063877017,
"time_unix_nano": 1743544747902934616,
"value": 2,
"exemplars": []
}
],
"aggregation_temporality": 2,
"is_monotonic": true
}
}
],
"schema_url": ""
}
],
"schema_url": ""
}
]
}
[INFO]	2025-04-01T21:59:07.903Z	0dd2717b-621c-4bd1-ac58-2013e88a33e0	Lambda invoked
{
"name": "test-span",
"context": {
"trace_id": "0xdcd97cb4feeaebdabd22294a77f7e8cc",
"span_id": "0x6a9e5f1a735f47ae",
"trace_state": "[]"
},
"kind": "SpanKind.INTERNAL",
"parent_id": null,
"start_time": "2025-04-01T21:59:07.903972Z",
"end_time": "2025-04-01T21:59:08.004132Z",
"status": {
"status_code": "UNSET"
},
"attributes": {
"custom.attribute": "test-otel"
},
"events": [],
"links": [],
"resource": {
"attributes": {
"telemetry.sdk.language": "python",
"telemetry.sdk.name": "opentelemetry",
"telemetry.sdk.version": "1.30.0",
"service.name": "otel-py313-test"
},
"schema_url": ""
}
}
END RequestId: TRUNCATED-2013e88a33e0
REPORT RequestId: TRUNCATED-2013e88a33e0	Duration: 102.59 ms	Billed Duration: 103 ms	Memory Size: 128 MB	Max Memory Used: 61 MB

Request ID: TRUNCATED-2013e88a33e0

Please let me know what else I can provide.

Thank you!

@serkan-ozal
Copy link
Contributor

Thanks for the contribution @imanshafiei540

@serkan-ozal serkan-ozal merged commit 1f1778c into open-telemetry:main Apr 4, 2025
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for Python 3.13

2 participants