Skip to content

WIP: add a package for structlog handler#2139

Closed
Samyak2 wants to merge 2 commits intoopen-telemetry:mainfrom
Samyak2:opentelemetry-structlog
Closed

WIP: add a package for structlog handler#2139
Samyak2 wants to merge 2 commits intoopen-telemetry:mainfrom
Samyak2:opentelemetry-structlog

Conversation

@Samyak2
Copy link
Copy Markdown

@Samyak2 Samyak2 commented Jan 28, 2024

Description

Closes open-telemetry/opentelemetry-python#2993

A few notes about this handler:

  • A similar set up has been used in prod with Signoz
  • Some things may be specific to Signoz
  • Uses some things from private modules in both structlog and opentelemetry-sdk

TODO

  • Add a new package with the handler/processor
  • Add tests
  • Publish this package to PyPI

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • Test A

Does This PR Require a Core Repo Change?

  • Yes. - Link to PR:
  • No.

Checklist:

See contributing.md for styleguide, changelog guidelines, and more.

  • Followed the style guidelines of this project
  • Changelogs have been updated
  • Unit tests have been added
  • Documentation has been updated

@linux-foundation-easycla
Copy link
Copy Markdown

linux-foundation-easycla bot commented Jan 28, 2024

CLA Signed

The committers listed above are authorized under a signed CLA.

@JamesHutchison
Copy link
Copy Markdown

JamesHutchison commented Apr 1, 2024

If you're like me and you're trying to figure out how to get this working, here's what I have that seems to be working with honeycomb.io:

import socket

from opentelemetry.exporter.otlp.proto.grpc._log_exporter import (
    OTLPLogExporter,
)

...

    structlog.configure(
        cache_logger_on_first_use=True,
        wrapper_class=structlog.make_filtering_bound_logger(logging.INFO),
        processors=[
            structlog.contextvars.merge_contextvars,
            structlog.processors.add_log_level,
            # structlog.processors.format_exc_info,
            # structlog.processors.TimeStamper(fmt="iso", utc=True),
            OpenTelemetryExporter(
                os.environ.get("OTEL_SERVICE_NAME") or "",
                socket.gethostname(),
                OTLPLogExporter(),
            ),
            structlog.processors.JSONRenderer(serializer=orjson.dumps),
        ],
        logger_factory=structlog.BytesLoggerFactory(),
    )

That logic needs cleanup but hopefully this helps someone.

classifiers = [
"Development Status :: 4 - Beta",
"Intended Audience :: Developers",
"License :: OSI Approved :: Apache Software License",
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

License classifiers are deprecated.

@github-actions
Copy link
Copy Markdown

This PR has been automatically marked as stale because it has not had any activity for 14 days. It will be closed if no further activity occurs within 14 days of this comment.
If you're still working on this, please add a comment or push new commits.

@github-actions github-actions bot added the Stale label Mar 11, 2026
@github-actions
Copy link
Copy Markdown

This PR has been closed due to inactivity. Please reopen if you would like to continue working on it.

@github-actions github-actions bot closed this Mar 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add handler for structlog

3 participants