Digma instrumentation for Python
Project description
opentelemetry-instrumenation-digma
This package provides instrumentation helpers and tools to make it easy to set up Digma to work along with your OpenTelemetry instrumentation.
In order to be able to effectively glean code-object based insights for continuous feedback and map them back in the IDE, Digma inserts additional attribute into the OTEL resource attributes.
Instrumenting existing projects
The Digma instrumentation helper configuration options
Installing the package
pip install opentelemetry-instrumentation-digma
Instrumenting an existing project
If you are introducing both OTEL and Digma
To make it convenient to get started quickly with some default for both OpenTelemetry and Digma, a quick bootsrap function is provided. This is not intended for usage if you already have OpenTelmetry set up in your project, nor be used as a production configuration.
from opentelemetry.instrumentation.digma import digma_opentelemetry_boostrap
digma_opentelemetry_boostrap(service_name='server-name', digma_backend="http://localhost:5050",
configuration=DigmaConfiguration().trace_this_package())
If you are already using OpenTelemtry tracing in your project
If you have an existing OpenTelemtry instrumentaiton set up, simply use the DigmaConfiguration object to create a Resource
object and merge it with your resource to import all of the needed attributes.
resource = Resource.create(attributes={SERVICE_NAME: service_name})
resource = resource.merge(DigmaConfiguration().trace_this_package())
You can use a standard OTLP exporter to the Digma collector for local deployments:
exporter = OTLPSpanExporter(endpoint="localhost:5050", insecure=True)
provider.add_span_processor(BatchSpanProcessor(exporter))
Alternatively, if you're already using a collector component you can simply modify its configuration file:
exporters:
...
otlp/digma:
endpoint: "localhost:5050"
tls:
insecure: true
service:
pipelines:
traces:
exporters: [otlp/digma, ...]
Building the package from source
python -m build
The Digma instrumentation helper configuration options
Setting | Description | Default |
---|---|---|
set_environment |
Set the identifier of the deployment environment for the current trace process. e.g. 'staging', 'ci' | Will try to read from env variable, otherwies 'UNSET' |
set_commit_id |
Allows setting the commit identifier for the currently executing code. | Will try to read from env variable otherwise empty |
use_env_variable_for_commit_id |
Set a custom environment variable to read the commit identifier from in runtime. | 'GIT_COMMIT_ID' |
use_env_variable_for_deployment_environment |
Set a custom environment variable to read the deployment environment identifier from in runtime. | 'DEPLOYMENT_ENV' |
trace_this_package |
Specify the current package root folder. Used to aligned tracing with code | None |
trace_package |
Specify additional satellite or infra packages to track | None |
The tracing decorator
The digma package include an optional tracing decorator intended to make span declarations easier and less repetitive. You can use the decorator at the function or class level to specify a span should be automatically created.
The decorator will automatically add additional context for each span based on the wrapped method.
Example usage:
@instrument
def standalone_function(self):
# Will create a span named 'standalone_function' (default naming)
pass
@instrument(attributes={"one": "two"})
class SomeClass:
@instrument(span_name="function_decorator", attributes={"two": "three"})
def function_one(self):
# Will create a span named 'function_decorator' with above attributes
pass
def function_two(self):
# Will create a span named 'function_two', since SomeClass has decorator
pass
def _function_three(self):
# Will not create a span for this function as it is private
pass
@instrument(ignore=True)
def do_not_instrument(self):
# Will not create a span for this function as it is set to ignore
pass
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for opentelemetry-instrumentation-digma-0.9.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 64f2f303fef8e58fb9512f72e1ab498ddb2f2b801d1368b3af6bf4771c24e26c |
|
MD5 | b213859e83518d5b7235b6807824b23e |
|
BLAKE2b-256 | ff67529bf1df8719cba49bcf5b47f78f2489a52ace21b1b1ecf38c640b0209dd |
Hashes for opentelemetry_instrumentation_digma-0.9.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 78441223012635f1da2cd49e8f526de56895ecac52725287088cb1bf1d23edaf |
|
MD5 | 5c8434c8e0b49eb09006190859f9ca30 |
|
BLAKE2b-256 | 39b92c07b125af5954e59cbc3cfba94bc605878e454976ed5f18e745bc65551a |