Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Implementation for otlp udp exporter #261

Merged
merged 7 commits into from
Mar 4, 2025

Conversation

jj22ee
Copy link
Contributor

@jj22ee jj22ee commented Feb 27, 2025

Description:

Implementing a Golang UDP exporter for OTLP spans for an AWS Lambda environment.

  • OTel spans is first protobuf encoded, then base64 encoded, then prefixed with T1S (Sampled Spans Prefix), and finally appended to the '{"format":"json","version":1}\n' string before being exported to the address provided to the UDP Exporter or default 127.0.0.1:2000.
  • UDP Exporter class name otlptraceudp follows OTel Go exporters like otlptracegrpc and otlptracehttp
  • If in an AWS Lambda Environment, use AWS_XRAY_DAEMON_ADDRESS env var as the default address instead of 127.0.0.1:2000.

Link to tracking Issue:

Testing:

cd ./exporters/otlptraceudp
go test ./...

image

Tested with OTel Sample App for Lambda Go: https://github.com/open-telemetry/opentelemetry-lambda/blob/main/go/sample-apps/function/function.go
Updated TracerProvider to be like:

	daemonAddress := os.Getenv("AWS_XRAY_DAEMON_ADDRESS")
	myudpexporter, _ := otlptraceudp.New(ctx, otlptraceudp.WithEndpoint(daemonAddress))

	tp := trace.NewTracerProvider(trace.WithSpanProcessor(trace.NewSimpleSpanProcessor(myudpexporter)))

Raw span from Lambda

{
    "Id": "1-67c0d852-210aa54e1b267ff37ce7f51b",
    "Duration": 0.125,
    "LimitExceeded": false,
    "Segments": [
        {
            "Id": "0289ef4deea9b744",
            "Document": {
                "id": "0289ef4deea9b744",
                "name": "go-udp-testing",
                "start_time": 1740691538.571,
                "trace_id": "1-67c0d852-210aa54e1b267ff37ce7f51b",
                "end_time": 1740691538.696,
                "http": {
                    "response": {
                        "status": 200
                    }
                },
                "aws": {
                    "request_id": "9e463e5f-eb23-43a3-b3bb-61c63fe55225"
                },
                "origin": "AWS::Lambda",
                "resource_arn": "arn:aws:lambda:us-east-1:123456789012:function:go-udp-testing"
            }
        },
        {
            "Id": "36b27711568a12dc",
            "Document": {
                "id": "36b27711568a12dc",
                "name": "go-udp-testing",
                "start_time": 1740691538.576232,
                "trace_id": "1-67c0d852-210aa54e1b267ff37ce7f51b",
                "end_time": 1740691538.6961966,
                "parent_id": "0289ef4deea9b744",
                "aws": {
                    "account_id": "123456789012",
                    "function_arn": "arn:aws:lambda:us-east-1:123456789012:function:go-udp-testing",
                    "cloudwatch_logs": [
                        {
                            "log_group": "/aws/lambda/go-udp-testing"
                        }
                    ],
                    "resource_names": [
                        "go-udp-testing"
                    ]
                },
                "origin": "AWS::Lambda::Function",
                "subsegments": [
                    {
                        "id": "0716f80c05e26051",
                        "name": "Invocation",
                        "start_time": 1740691538.576332,
                        "end_time": 1740691538.6958847,
                        "aws": {
                            "function_arn": "arn:aws:lambda:us-east-1:123456789012:function:go-udp-testing"
                        }
                    },
                    {
                        "id": "a2e43621571698fb",
                        "name": "Overhead",
                        "start_time": 1740691538.6959248,
                        "end_time": 1740691538.6961403,
                        "aws": {
                            "function_arn": "arn:aws:lambda:us-east-1:123456789012:function:go-udp-testing"
                        }
                    }
                ]
            }
        },
        {
            "Id": "b113328b83442634",
            "Document": {
                "id": "b113328b83442634",
                "name": "unknown_service:bootstrap",
                "start_time": 1740691538.576584,
                "trace_id": "1-67c0d852-210aa54e1b267ff37ce7f51b",
                "end_time": 1740691538.6255057,
                "parent_id": "0716f80c05e26051",
                "aws": {
                    "lambda.invoked_arn": "arn:aws:lambda:us-east-1:123456789012:function:go-udp-testing"
                },
                "annotations": {
                    "span.name": "go-udp-testing",
                    "span.kind": "SERVER"
                },
                "metadata": {
                    "telemetry.sdk.language": "go",
                    "faas.invocation_id": "9e463e5f-eb23-43a3-b3bb-61c63fe55225",
                    "service.name": "unknown_service:bootstrap",
                    "cloud.account.id": "123456789012",
                    "telemetry.sdk.version": "1.34.0",
                    "telemetry.sdk.name": "opentelemetry"
                },
                "subsegments": [
                    {
                        "id": "d87989e76f7c69cc",
                        "name": "HTTP GET",
                        "start_time": 1740691538.6223142,
                        "end_time": 1740691538.6250916,
                        "http": {
                            "request": {
                                "url": "https://api.github.com/repos/open-telemetry/opentelemetry-go/releases/latest",
                                "method": "GET"
                            },
                            "response": {
                                "status": 200
                            }
                        },
                        "annotations": {
                            "span.name": "HTTP GET",
                            "span.kind": "CLIENT"
                        },
                        "metadata": {
                            "net.peer.name": "api.github.com",
                            "http.status_code": 200,
                            "telemetry.sdk.language": "go",
                            "service.name": "unknown_service:bootstrap",
                            "http.url": "https://api.github.com/repos/open-telemetry/opentelemetry-go/releases/latest",
                            "telemetry.sdk.version": "1.34.0",
                            "http.method": "GET",
                            "telemetry.sdk.name": "opentelemetry"
                        },
                        "namespace": "remote"
                    },
                    {
                        "id": "c82ce0147e264b58",
                        "name": "S3",
                        "start_time": 1740691538.5766907,
                        "end_time": 1740691538.6221228,
                        "http": {
                            "response": {
                                "status": 200
                            }
                        },
                        "aws": {
                            "region": "us-east-1",
                            "request_id": "ZYPJZ1QBG7NDBYN2"
                        },
                        "annotations": {
                            "span.name": "S3.ListBuckets",
                            "span.kind": "CLIENT"
                        },
                        "metadata": {
                            "http.status_code": 200,
                            "telemetry.sdk.language": "go",
                            "service.name": "unknown_service:bootstrap",
                            "rpc.service": "S3",
                            "rpc.method": "ListBuckets",
                            "telemetry.sdk.version": "1.34.0",
                            "rpc.system": "aws-api",
                            "telemetry.sdk.name": "opentelemetry"
                        },
                        "namespace": "aws"
                    }
                ]
            }
        },
        {
            "Id": "010fdb49177e6f32",
            "Document": {
                "id": "010fdb49177e6f32",
                "name": "HTTP GET",
                "start_time": 1740691538.6223142,
                "trace_id": "1-67c0d852-210aa54e1b267ff37ce7f51b",
                "end_time": 1740691538.6250916,
                "parent_id": "d87989e76f7c69cc",
                "inferred": true,
                "http": {
                    "request": {
                        "url": "https://api.github.com/repos/open-telemetry/opentelemetry-go/releases/latest",
                        "method": "GET"
                    },
                    "response": {
                        "status": 200
                    }
                }
            }
        },
        {
            "Id": "1c6e82bf212279b5",
            "Document": {
                "id": "1c6e82bf212279b5",
                "name": "S3",
                "start_time": 1740691538.5766907,
                "trace_id": "1-67c0d852-210aa54e1b267ff37ce7f51b",
                "end_time": 1740691538.6221228,
                "parent_id": "c82ce0147e264b58",
                "inferred": true,
                "http": {
                    "response": {
                        "status": 200
                    }
                },
                "aws": {
                    "region": "us-east-1",
                    "request_id": "ZYPJZ1QBG7NDBYN2"
                },
                "origin": "AWS::S3"
            }
        }
    ]
}

Documentation:

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@jj22ee jj22ee requested a review from a team February 27, 2025 21:37
Copy link

@lukeina2z lukeina2z left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great. Please measure the test coverage before the merge 'go test -cover ./...'

@jj22ee jj22ee force-pushed the udp-exporter branch 4 times, most recently from 6cac3d1 to adeb6f8 Compare March 1, 2025 02:48
@jj22ee jj22ee merged commit 343d2ab into aws-observability:main Mar 4, 2025
16 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.

3 participants