Skip to main content

Form Energy Observability Python Library

OTel tracing and logging tools, emphasizing data pipeline use cases with Dagster.

Using the Library

Install from PyPI

pip install formenergy-observability

Features

See the examples/ directory for examples you can run and screenshots of the traces they produce.

Some key features demonstrated in the examples:

Context-aware tracing, so that spans and events can inherit attributes from parents:

from form_observability import ContextAwareTracer, ctx

_trace = ContextAwareTracer(__name__)

with ctx.set({"my_attribute_name": my_attribute_value}):
    # There could be many intervening function calls and spans.
    # Spans and events in this context automatically have the my_attribute_name
    # attribute set on them.
    _trace.add_event("my_event")

Trace context propagation for Dagster ops:

from form_observability.dagster_otel import otel_op, publish_current_trace_context
from form_observability import ContextAwareTracer

_trace = ContextAwareTracer(__name__)

@op
def root_trace_context_op(context):
    with _trace.start_as_current_span("root"):
        # writes the trace context (as an asset materialization event) for later ops
        publish_current_trace_context(context)

@otel_op()  # picks up the trace context and starts a new span for this op
def my_op(context):
    _trace.add_event("my_event")

@graph
def my_graph()
    # In the graph, publish a root trace using a regular op, and then subsequent
    # @otel_op ops will pick it up and contribute to the same trace.
    setup_done = root_trace_context_op()
    my_op(start=setup_done)

Running the Examples

Get an API key for uploading traces to your observability service (preferably in a development environment), set it in your environment, and run the examples. This should publish traces that you can then view.

export OTEL_EXPORTER_OTLP_HEADERS_JSON="{'x-honeycomb-team': '<API key>'}"
export OTEL_EXPORTER_OTLP_ENDPOINT="your observability service, defaults to Honeycomb"
python examples/basics.py
dagster job execute --python-file examples/dagster_job.py

License

This library is provided under the MIT license, see LICENSE.

Release Notes

  • 0.3.2 Update grpcio minimum dependency version to 1.48.1 and dagster to 1.5.0. Thanks @dang-kaiko !
  • 0.3.1 Fix type used for otlp_headers to be a dict. Thanks @spenczar !
  • 0.3.0 Add ContextAwareTracer.start_new_linked_trace.
  • 0.2.0 Switch to context.op_handle and materialization.metadata as dict for Dagster 1.2.
  • 0.1.0 Initial external release, including ContextAwareTracer, ctx, and @otel_op.

Development

If you contribute, please ensure you and your employer accept the license for any of your contributions.

Setup

Create and activate a virtual environment with your favorite tool, such as direnv. This project requires Python 3.8.

pip install flit
flit install --deps all --symlink [--python /path/to/venv/python]

By default, flit installs into the current virtual environment. Using the --python argument can let you install into a specific venv other than the currently active one. For example you can activate some other venv, run which python, and then pass the output of that command to flit's --python argument when installing from the form-observability repo.

Initialize pre-commit hooks:

pre-commit install --hook-type pre-commit --hook-type pre-push

Running Tests

From the project root directory:

pytest

Metadata

Release files for formenergy-observability 0.3.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for formenergy-observability 0.3.2
File Size Uploaded Provenance Actions
formenergy_observability-0.3.2.tar.gz 304.6 kB Without provenance Details for formenergy_observability-0.3.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for formenergy-observability 0.3.2
File Interpreter ABI Platform Actions
formenergy_observability-0.3.2-py3-none-any.whl Python 3 none any Details for formenergy_observability-0.3.2-py3-none-any.whl

Total release size: 325.3 kB

Release files / formenergy_observability-0.3.2.tar.gz

Download URL formenergy_observability-0.3.2.tar.gz
Size 304.6 kB
Tags Source
SHA-256 checksum
How to use checksums
73a3cb542d8cb354b811cab785b154602a08665d0f5dd18441c286053581198e
BLAKE2b-256 checksum
How to use checksums
f0138a1866c23b3de89f4313afa12233ebda5bde2555d3b0d6e9686780a851d6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.31.0

Release files / formenergy_observability-0.3.2-py3-none-any.whl

Download URL formenergy_observability-0.3.2-py3-none-any.whl
Size 20.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f77dbdd8170a353b25b0224e362272dff1ca5191459a50a7da612c659fc626f2
BLAKE2b-256 checksum
How to use checksums
f49d3be81dcd76503326c74b4a1ffa63d2cc732e406748a8719b751ccbd46ab9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.31.0

Security for formenergy-observability 0.3.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page