Skip to content

Add BatchUnsampledSpanProcessor for exporting unsampled spans #42

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

Merged
merged 1 commit into from
Sep 11, 2024

Conversation

mxiamxia
Copy link
Member

Description of changes:

  1. Implemented a new AwsBatchUnsampledSpanProcessor to only export unsampled spans(TraceFlags.SAMPLED !==1)
  2. Registered it as an additional SpanProcessor for TraceProvider
  3. Add different Prefixes for sampled/unsampled OTel span when sending to FluxPump
    • Sampled Spans Prefix - T1S
    • Unsampled Spans Prefix - T1U

Test
X-Ray data example

{
    "Id": "1-66e11092-767bc32c5717c925604e37e3",
    "Duration": 0.158,
    "LimitExceeded": false,
    "Segments": [
        {
            "Id": "5a5e9957e3a068ef",
            "Document": {
                "id": "5a5e9957e3a068ef",
                "name": "aws-opentelemetry-distro-nodejs",
                "start_time": 1726025874.375,
                "trace_id": "1-66e11092-767bc32c5717c925604e37e3",
                "end_time": 1726025874.527,
                "parent_id": "5ff5cfd8f1c6ed59",
                "http": {
                    "response": {
                        "status": 200
                    }
                },
                "aws": {
                    "request_id": "e4ac3af9-7538-4b8c-84c8-36d154378813"
                },
                "origin": "AWS::Lambda",
                "resource_arn": "arn:aws:lambda:us-west-2:252610625673:function:aws-opentelemetry-distro-nodejs"
            }
        },
        {
            "Id": "30e074d0013a9b6f",
            "Document": {
                "id": "30e074d0013a9b6f",
                "name": "aws-opentelemetry-distro-nodejs/default",
                "start_time": 1726025874.369,
                "trace_id": "1-66e11092-767bc32c5717c925604e37e3",
                "end_time": 1726025874.527,
                "http": {
                    "request": {
                        "url": "https://aixsrfz8n8.execute-api.us-west-2.amazonaws.com/default",
                        "method": "GET",
                        "user_agent": "curl/8.7.1",
                        "client_ip": "205.251.233.233",
                        "x_forwarded_for": true
                    },
                    "response": {
                        "status": 200,
                        "content_length": 0
                    }
                },
                "aws": {
                    "xray": {
                        "sampling_rule_name": "Default"
                    },
                    "api_gateway": {
                        "account_id": "252610625673",
                        "rest_api_id": "aixsrfz8n8",
                        "stage": "default",
                        "request_id": "41da0ef6-b16c-45e9-9334-a11347f5dec7"
                    }
                },
                "annotations": {
                    "aws:api_id": "aixsrfz8n8",
                    "aws:api_stage": "default"
                },
                "metadata": {
                    "default": {
                        "extended_request_id": "d6-G6FsovHcEMoQ=",
                        "request_id": "41da0ef6-b16c-45e9-9334-a11347f5dec7"
                    }
                },
                "origin": "AWS::ApiGateway::Stage",
                "resource_arn": "arn:aws:apigateway:us-west-2::/restapis/aixsrfz8n8/stages/default",
                "subsegments": [
                    {
                        "id": "5ff5cfd8f1c6ed59",
                        "name": "Lambda",
                        "start_time": 1726025874.371,
                        "end_time": 1726025874.527,
                        "http": {
                            "request": {
                                "url": "https://lambda.us-west-2.amazonaws.com/2015-03-31/functions/arn:aws:lambda:us-west-2:252610625673:function:aws-opentelemetry-distro-nodejs/invocations",
                                "method": "ANY"
                            },
                            "response": {
                                "status": 200,
                                "content_length": 120
                            }
                        },
                        "aws": {
                            "function_name": "aws-opentelemetry-distro-nodejs",
                            "region": "us-west-2",
                            "operation": "Invoke",
                            "resource_names": [
                                "aws-opentelemetry-distro-nodejs"
                            ]
                        },
                        "namespace": "aws"
                    }
                ]
            }
        },
        {
            "Id": "7197ce026d312a49",
            "Document": {
                "id": "7197ce026d312a49",
                "name": "aws-opentelemetry-distro-nodejs",
                "start_time": 1726025874.3797677,
                "trace_id": "1-66e11092-767bc32c5717c925604e37e3",
                "end_time": 1726025874.5265381,
                "parent_id": "5a5e9957e3a068ef",
                "aws": {
                    "account_id": "252610625673",
                    "function_arn": "arn:aws:lambda:us-west-2:252610625673:function:aws-opentelemetry-distro-nodejs",
                    "cloudwatch_logs": [
                        {
                            "log_group": "/aws/lambda/aws-opentelemetry-distro-nodejs"
                        }
                    ],
                    "resource_names": [
                        "aws-opentelemetry-distro-nodejs"
                    ]
                },
                "origin": "AWS::Lambda::Function",
                "subsegments": [
                    {
                        "id": "ca73bcb9d61476de",
                        "name": "Invocation",
                        "start_time": 1726025874.3798523,
                        "end_time": 1726025874.5261395,
                        "aws": {
                            "function_arn": "arn:aws:lambda:us-west-2:252610625673:function:aws-opentelemetry-distro-nodejs"
                        }
                    },
                    {
                        "id": "4153b4f45ff3b1e8",
                        "name": "Overhead",
                        "start_time": 1726025874.5261652,
                        "end_time": 1726025874.5264673,
                        "aws": {
                            "function_arn": "arn:aws:lambda:us-west-2:252610625673:function:aws-opentelemetry-distro-nodejs"
                        }
                    }
                ]
            }
        },
        {
            "Id": "ae60d7baedc1cfb5",
            "Document": {
                "id": "ae60d7baedc1cfb5",
                "name": "aws-opentelemetry-distro-nodejs",
                "start_time": 1726025874.38,
                "trace_id": "1-66e11092-767bc32c5717c925604e37e3",
                "end_time": 1726025874.5246706,
                "parent_id": "ca73bcb9d61476de",
                "aws": {
                    "trace.flag.unsampled": true,
                    "is.local.root": true
                },
                "annotations": {
                    "span.kind": "SERVER"
                },
                "metadata": {
                    "faas.id": "arn:aws:lambda:us-west-2:252610625673:function:aws-opentelemetry-distro-nodejs",
                    "cloud.account.id": "252610625673",
                    "faas.execution": "e4ac3af9-7538-4b8c-84c8-36d154378813"
                },
                "subsegments": [
                    {
                        "id": "328592d80ebf7e72",
                        "name": "GET",
                        "start_time": 1726025874.483,
                        "end_time": 1726025874.5237389,
                        "aws": {
                            "trace.flag.unsampled": true,
                            "local.operation": "aws-opentelemetry-distro-nodejs",
                            "is.local.root": false
                        },
                        "annotations": {
                            "span.kind": "CLIENT"
                        },
                        "metadata": {
                            "net.transport": "ip_tcp",
                            "net.peer.name": "jsonplaceholder.typicode.com",
                            "http.status_code": 200,
                            "net.peer.port": 443,
                            "http.target": "/todos/1",
                            "http.flavor": "1.1",
                            "http.url": "https://jsonplaceholder.typicode.com/todos/1",
                            "http.status_text": "OK",
                            "net.peer.ip": "104.21.59.19",
                            "http.method": "GET",
                            "http.host": "jsonplaceholder.typicode.com:443"
                        },
                        "namespace": "remote"
                    },
                    {
                        "id": "6d998c5cf661c0ec",
                        "name": "S3.ListBuckets",
                        "start_time": 1726025874.381,
                        "end_time": 1726025874.4829986,
                        "aws": {
                            "signature.version": "s3",
                            "service.name": "Amazon S3",
                            "trace.flag.unsampled": true,
                            "local.operation": "aws-opentelemetry-distro-nodejs",
                            "service.api": "S3",
                            "region": "us-west-2",
                            "is.local.root": false,
                            "service.identifier": "s3",
                            "operation": "listBuckets",
                            "request.id": "XWEGH4NV5PMQZEHV"
                        },
                        "annotations": {
                            "span.kind": "CLIENT"
                        },
                        "metadata": {
                            "http.status_code": 200,
                            "rpc.service": "S3",
                            "rpc.method": "ListBuckets",
                            "rpc.system": "aws-api"
                        },
                        "namespace": "aws",
                        "subsegments": [
                            {
                                "id": "5b8e13800550b551",
                                "name": "GET",
                                "start_time": 1726025874.381,
                                "end_time": 1726025874.4812143,
                                "aws": {
                                    "trace.flag.unsampled": true,
                                    "local.operation": "aws-opentelemetry-distro-nodejs",
                                    "is.local.root": false,
                                    "sdk.descendant": "true"
                                },
                                "annotations": {
                                    "span.kind": "CLIENT"
                                },
                                "metadata": {
                                    "net.transport": "ip_tcp",
                                    "net.peer.name": "s3.us-west-2.amazonaws.com",
                                    "http.status_code": 200,
                                    "net.peer.port": 443,
                                    "http.target": "/",
                                    "http.flavor": "1.1",
                                    "http.url": "https://s3.us-west-2.amazonaws.com/",
                                    "http.status_text": "OK",
                                    "net.peer.ip": "52.218.178.96",
                                    "http.method": "GET",
                                    "http.host": "s3.us-west-2.amazonaws.com:443"
                                },
                                "namespace": "remote"
                            }
                        ]
                    }
                ]
            }
        },
        {
            "Id": "1c146cef33e14019",
            "Document": {
                "id": "1c146cef33e14019",
                "name": "GET",
                "start_time": 1726025874.381,
                "trace_id": "1-66e11092-767bc32c5717c925604e37e3",
                "end_time": 1726025874.4812143,
                "parent_id": "5b8e13800550b551",
                "inferred": true
            }
        },
        {
            "Id": "2bccb63c011d05ec",
            "Document": {
                "id": "2bccb63c011d05ec",
                "name": "GET",
                "start_time": 1726025874.483,
                "trace_id": "1-66e11092-767bc32c5717c925604e37e3",
                "end_time": 1726025874.5237389,
                "parent_id": "328592d80ebf7e72",
                "inferred": true
            }
        }
    ]
}

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@mxiamxia mxiamxia force-pushed the min-dev-lambda-unsampled branch from 13e0cd3 to 07ae012 Compare September 11, 2024 03:43
@mxiamxia mxiamxia force-pushed the min-dev-lambda-unsampled branch from 07ae012 to 45e0dfb Compare September 11, 2024 03:57
@mxiamxia mxiamxia assigned mxiamxia and wangzlei and unassigned mxiamxia and wangzlei Sep 11, 2024
@mxiamxia mxiamxia marked this pull request as ready for review September 11, 2024 04:31
@mxiamxia mxiamxia requested a review from a team as a code owner September 11, 2024 04:31
@mxiamxia mxiamxia merged commit 3b264f5 into main Sep 11, 2024
6 checks passed
@mxiamxia mxiamxia deleted the min-dev-lambda-unsampled branch September 11, 2024 04:34
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.

2 participants