{"id":14791,"library":"opencensus-proto","title":"OpenCensus Proto Definitions","description":"The `opencensus-proto` library provides the Python-generated Protobuf definitions for the OpenCensus project. These definitions cover tracing, metrics, and agent protocols. While the GitHub repository for the proto definitions is actively maintained, the Python package on PyPI (version 0.1.0) has not been updated since 2019. OpenCensus itself has been officially deprecated in favor of OpenTelemetry.","status":"deprecated","version":"0.1.0","language":"en","source_language":"en","source_url":"https://github.com/census-instrumentation/opencensus-proto/tree/master/gen-python","tags":["protobuf","opencensus","telemetry","tracing","metrics","deprecated"],"install":[{"cmd":"pip install opencensus-proto","lang":"bash","label":"Install stable version"}],"dependencies":[],"imports":[{"note":"Protobuf generated files follow a `_pb2` suffix pattern and are typically imported directly.","wrong":"import opencensus.proto.trace.v1.trace","symbol":"trace_pb2","correct":"from opencensus.proto.trace.v1 import trace_pb2"},{"note":"Access generated protobuf message classes directly from the `_pb2` module.","wrong":"from opencensus.proto.metrics.v1.metrics import metrics","symbol":"metrics_pb2","correct":"from opencensus.proto.metrics.v1 import metrics_pb2"},{"note":"gRPC service definitions are generated with a `_pb2_grpc` suffix.","wrong":"from opencensus.proto.agent.trace.v1 import trace_service","symbol":"agent_trace_service_pb2_grpc","correct":"from opencensus.proto.agent.trace.v1 import trace_service_pb2_grpc"}],"quickstart":{"code":"import sys\nfrom opencensus.proto.trace.v1 import trace_pb2\n\n# Create a Span message\nspan = trace_pb2.Span(\n    trace_id=b'0123456789abcdef0123456789abcdef',\n    span_id=b'fedcba9876543210',\n    name=trace_pb2.TruncatableString(value='my_span_name'),\n    kind=trace_pb2.Span.SPAN_KIND_CLIENT,\n    start_time={'seconds': 1678886400, 'nanos': 0},\n    end_time={'seconds': 1678886400, 'nanos': 100000000}\n)\n\nprint(f\"Created Span name: {span.name.value}\")\nprint(f\"Span ID: {span.span_id.hex()}\")\n\n# To serialize to bytes\nserialized_span = span.SerializeToString()\nprint(f\"Serialized Span (first 20 bytes): {serialized_span[:20]}\")\n\n# To parse from bytes\nparsed_span = trace_pb2.Span()\nparsed_span.ParseFromString(serialized_span)\nprint(f\"Parsed Span name: {parsed_span.name.value}\")","lang":"python","description":"This example demonstrates how to import a Protobuf message definition (e.g., `Span`) and instantiate it. Since `opencensus-proto` only provides definitions, usage primarily involves creating and manipulating these message objects."},"warnings":[{"fix":"Consider migrating to the OpenTelemetry Python SDK (opentelemetry-sdk) and its associated proto definitions (opentelemetry-proto).","message":"The OpenCensus project, including this library, has been officially deprecated in favor of OpenTelemetry. New applications should use OpenTelemetry for observability.","severity":"breaking","affected_versions":"All versions"},{"fix":"If you require the latest proto definitions, you would need to generate the Python code yourself from the `opencensus-proto` GitHub repository, or switch to OpenTelemetry.","message":"The `opencensus-proto` package on PyPI (version 0.1.0) is severely outdated compared to the latest proto definitions in the GitHub repository (v0.4.x). This means the Python-generated code available via PyPI does not contain the latest OpenCensus proto features or bug fixes.","severity":"gotcha","affected_versions":"0.1.0 and likely older"},{"fix":"Always import specific message modules with the `_pb2` suffix, e.g., `from opencensus.proto.trace.v1 import trace_pb2`.","message":"Protobuf messages are typically imported from generated `_pb2.py` files. Attempting to import them directly from a directory or without the `_pb2` suffix will result in a `ModuleNotFoundError` or `AttributeError`.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"Ensure `pip install opencensus-proto` has been run. Verify the full import path, including the version subdirectory and `_pb2` suffix, e.g., `from opencensus.proto.trace.v1 import trace_pb2`.","cause":"The `opencensus-proto` package is either not installed or the import path is incorrect. You might be missing the `v1` subdirectory or the `_pb2` suffix.","error":"ModuleNotFoundError: No module named 'opencensus.proto.trace'"},{"fix":"Double-check the message name (e.g., `Span` vs `span`) for case sensitivity. If the message genuinely seems missing, check the `opencensus-proto` GitHub repository for the proto definition's existence and consider the PyPI version discrepancy warning. You might be trying to use a message from a newer proto definition with an older Python package.","cause":"This error is unlikely for standard generated protos. However, it could occur if you're trying to access a message that doesn't exist in the imported module, or if you're trying to access it from an incorrect module. For OpenCensus, it's possible you're using an older PyPI version that doesn't contain a specific message type present in newer proto definitions.","error":"AttributeError: module 'opencensus.proto.trace.v1.trace_pb2' has no attribute 'Span'"}],"ecosystem":"pypi"}