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

feat(sdk): add OpenTelemetry logging support #2112

Merged
merged 3 commits into from
Oct 11, 2024

Conversation

jinsongo
Copy link
Contributor

@jinsongo jinsongo commented Oct 10, 2024

  • I have added tests that cover my changes.
  • If adding a new instrumentation or changing an existing one, I've added screenshots from some observability platform showing the change.
  • PR name follows conventional commits format: feat(instrumentation): ... or fix(instrumentation): ....
  • (If applicable) I have updated the documentation accordingly.

I set the default value to false for is_logging_enable() because the OpenTelemetry logging SDK is currently experimental.
The following is the console output from my test with logging enabled.

{
    "body": "Ask a question from Bedrock ...",
    "severity_number": "<SeverityNumber.INFO: 9>",
    "severity_text": "INFO",
    "attributes": {
        "otelSpanID": "0",
        "otelTraceID": "0",
        "otelTraceSampled": false,
        "otelServiceName": "chat_bot_service",
        "code.filepath": "/Users/jinsong/github.com/langX101/aws/./ut.py",
        "code.function": "<module>",
        "code.lineno": 218
    },
    "dropped_attributes": 0,
    "timestamp": "2024-10-10T22:42:59.598457Z",
    "observed_timestamp": "2024-10-10T22:42:59.598479Z",
    "trace_id": "0x00000000000000000000000000000000",
    "span_id": "0x0000000000000000",
    "trace_flags": 0,
    "resource": {
        "attributes": {
            "telemetry.sdk.language": "python",
            "telemetry.sdk.name": "opentelemetry",
            "telemetry.sdk.version": "1.27.0",
            "service.name": "chat_bot_service"
        },
        "schema_url": ""
    }
}
{
    "body": "Found credentials in environment variables.",
    "severity_number": "<SeverityNumber.INFO: 9>",
    "severity_text": "INFO",
    "attributes": {
        "otelSpanID": "bebfe1109ce1317b",
        "otelTraceID": "e4beafab532fb6a434d9f8f3a3b6bc57",
        "otelTraceSampled": true,
        "otelServiceName": "chat_bot_service",
        "code.filepath": "/Users/jinsong/.pyenv/versions/3.11.5/lib/python3.11/site-packages/botocore/credentials.py",
        "code.function": "load",
        "code.lineno": 1147
    },
    "dropped_attributes": 0,
    "timestamp": "2024-10-10T22:42:59.603841Z",
    "observed_timestamp": "2024-10-10T22:42:59.603864Z",
    "trace_id": "0xe4beafab532fb6a434d9f8f3a3b6bc57",
    "span_id": "0xbebfe1109ce1317b",
    "trace_flags": 1,
    "resource": {
        "attributes": {
            "telemetry.sdk.language": "python",
            "telemetry.sdk.name": "opentelemetry",
            "telemetry.sdk.version": "1.27.0",
            "service.name": "chat_bot_service"
        },
        "schema_url": ""
    }
}
{
    "body": "HTTP Request: GET https://en.wikipedia.org/w/api.php?action=query&list=search&srsearch=France&format=json \"HTTP/1.1 200 OK\"",
    "severity_number": "<SeverityNumber.INFO: 9>",
    "severity_text": "INFO",
    "attributes": {
        "otelSpanID": "71d2e872e690307e",
        "otelTraceID": "e4beafab532fb6a434d9f8f3a3b6bc57",
        "otelTraceSampled": true,
        "otelServiceName": "chat_bot_service",
        "code.filepath": "/Users/jinsong/.pyenv/versions/3.11.5/lib/python3.11/site-packages/httpx/_client.py",
        "code.function": "_send_single_request",
        "code.lineno": 1038
    },
    "dropped_attributes": 0,
    "timestamp": "2024-10-10T22:43:03.500336Z",
    "observed_timestamp": "2024-10-10T22:43:03.500543Z",
    "trace_id": "0xe4beafab532fb6a434d9f8f3a3b6bc57",
    "span_id": "0x71d2e872e690307e",
    "trace_flags": 1,
    "resource": {
        "attributes": {
            "telemetry.sdk.language": "python",
            "telemetry.sdk.name": "opentelemetry",
            "telemetry.sdk.version": "1.27.0",
            "service.name": "chat_bot_service"
        },
        "schema_url": ""
    }
}
{
    "body": "The question has been answered!",
    "severity_number": "<SeverityNumber.INFO: 9>",
    "severity_text": "INFO",
    "attributes": {
        "otelSpanID": "0",
        "otelTraceID": "0",
        "otelTraceSampled": false,
        "otelServiceName": "chat_bot_service",
        "code.filepath": "/Users/jinsong/github.com/langX101/aws/./ut.py",
        "code.function": "<module>",
        "code.lineno": 223
    },
    "dropped_attributes": 0,
    "timestamp": "2024-10-10T22:43:14.427116Z",
    "observed_timestamp": "2024-10-10T22:43:14.427211Z",
    "trace_id": "0x00000000000000000000000000000000",
    "span_id": "0x0000000000000000",
    "trace_flags": 0,
    "resource": {
        "attributes": {
            "telemetry.sdk.language": "python",
            "telemetry.sdk.name": "opentelemetry",
            "telemetry.sdk.version": "1.27.0",
            "service.name": "chat_bot_service"
        },
        "schema_url": ""
    }
}

@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. python Pull requests that update Python code labels Oct 10, 2024
@jinsongo
Copy link
Contributor Author

@nirga could you review the feature to comment if it is what we need for traceloop logging? Thanks. cc @gyliu513

@nirga
Copy link
Member

nirga commented Oct 11, 2024

Thanks @jinsongo
Yes it's a good start, we can then use it in the instrumentations to log prompts instead of the span attributes.

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Oct 11, 2024
@nirga nirga changed the title feat(logging): add OpenTelemetry logging support feat(sdk): add OpenTelemetry logging support Oct 11, 2024
@nirga nirga merged commit e373d2d into traceloop:main Oct 11, 2024
9 checks passed
@gyliu513
Copy link
Contributor

traceloop sdk update here #2112

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm This PR has been approved by a maintainer python Pull requests that update Python code size:L This PR changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants