Package: opentelemetry-instrumentation-digma
opentelemetry-instrumenation-digmaThis 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.Installing the packageInstrumenting existing projectsThe Digma instrumentation helper configuration optionsThe Tracing decoratorInstalling the packagepipinstallopentelemetry-instrumentation-digmaInstrumenting an existing projectIf you are introducing both OTEL and DigmaTo 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.fromopentelemetry.instrumentation.digmaimportdigma_opentelemetry_boostrapdigma_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 projectIf you have an existing OpenTelemtry instrumentaiton set up, simply use the DigmaConfiguration object to create aResourceobject 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:trueservice:pipelines:traces:exporters:[otlp/digma,...]Building the package from sourcepython-mbuildThe Digma instrumentation helper configuration optionsSettingDescriptionDefaultset_environmentSet 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_idAllows setting the commit identifier for the currently executing code.Will try to read from env variable otherwise emptyuse_env_variable_for_commit_idSet a custom environment variable to read the commit identifier from in runtime.'GIT_COMMIT_ID'use_env_variable_for_deployment_environmentSet a custom environment variable to read the deployment environment identifier from in runtime.'DEPLOYMENT_ENV'trace_this_packageSpecify the current package root folder. Used to aligned tracing with codeNonetrace_packageSpecify additional satellite or infra packages to trackNoneThe tracing decoratorThe 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:@instrumentdefstandalone_function(self):# Will create a span named 'standalone_function' (default naming)pass@instrument(attributes={"one":"two"})classSomeClass:@instrument(span_name="function_decorator",attributes={"two":"three"})deffunction_one(self):# Will create a span named 'function_decorator' with above attributespassdeffunction_two(self):# Will create a span named 'function_two', since SomeClass has decoratorpassdef_function_three(self):# Will not create a span for this function as it is privatepass@instrument(ignore=True)defdo_not_instrument(self):# Will not create a span for this function as it is set to ignorepass