Package: wavefront-opentracing-sdk-python
wavefront-opentracing-sdk-pythonTable of ContentRequirements and InstallationUsageApplication TagsWavefrontSenderReporterWavefrontTracerSpan LogsCross Process Context PropagationRED MetricsLicenseHow to ContributeWelcome to Wavefront's Python SDKThis is the Wavefront by VMware OpenTracing SDK for Python that provides distributed tracing support for Wavefront.The Wavefront OpenTracing SDK for Python automatically reports metrics, custom trace data, and derived metrics.Before you start implementing, let us make sure you are using the correct SDK!Note:This is the Wavefront by VMware OpenTracing SDK for Python!If this SDK is not what you were looking for, see thetablegiven below.Seeinstrument your application for tracingfor more information.Wavefront SDKsSDK TypeSDK DescriptionSupported LanguagesOpenTracing SDKImplements the OpenTracing specification. Lets you define, collect, and report custom trace data from any part of your application code.Automatically derives Rate Errors Duration (RED) metrics from the reported spans.Java:OpenTracing SDK|Tracing AgentPython:OpenTracing SDKGo:OpenTracing SDK.Net/C#:OpenTracing SDKMetrics SDKImplements a standard metrics library. Lets you define, collect, and report custom business metrics and histograms from any part of your application code.Java:Dropwizard|JVMPython:Pyformance SDKGo:Go Metrics SDK.Net/C#:App Metrics SDKFramework SDKReports predefined traces, metrics, and histograms from the APIs of a supported app framework. Lets you get started quickly with minimal code changes.Java:Dropwizard|gRPC|JAX-RS|Jersey.Net/C#:ASP.Net coreSender SDKLets you send raw values to Wavefront for storage as metrics, histograms, or traces, e.g., to import CSV data into Wavefront.Java:Sender SDKPython:Sender SDKGo:Sender SDK.Net/C#:Sender SDKC++:Sender SDKRequirements and InstallationThis SDK supports Python 3.x.pipinstallwavefront-opentracing-sdk-pythonUsageTraceris an OpenTracing interface for creating spans and propagating them across arbitrary transports.This SDK provides aWavefrontTracerto create spans and send them to Wavefront. TheWavefrontTraceralso automatically generates and reportsRED metricsfrom your spans.Follow these steps to create aWavefrontTracer:Create anApplicationTagsinstance, to specify metadata about your application.Create aWavefrontSenderinstanceto send trace data to Wavefront.Create aWavefrontSpanReporterinstanceto report trace data to Wavefront.Create theWavefrontTracerinstance.The following code sample creates a Tracer. For the details of each step, see the sections below.tracer=WavefrontTracer(reporter=reporter,application_tags=application_tags)1. Set Up Application TagsApplication tags describe the structure of your application. They are included with every span reported to Wavefront and are associated with span tags that you can use to filter and query trace data in Wavefront.You encapsulate application tags in anApplicationTagsobject.
SeeInstantiating ApplicationTags.2. Set Up a WavefrontSenderAWavefrontSenderobject implements the low-level interface for sending data to Wavefront. You can choose to send data using theWavefront proxyordirect ingestion.If you have already set up aWavefrontSenderfor another SDK that runs in the same process, use that one. (For details about sharing a Wavefront sender, seeShare a Wavefront Sender.Otherwise,Set Up a Wavefront Sender.3. Set Up a ReporterYou must create aWavefrontSpanReporterto report trace data to Wavefront. Optionally, you can create aCompositeReporterto send data to Wavefront and to print to the console.Create a WavefrontSpanReporterTo create aWavefrontSpanReporter:Specify the Wavefront sender fromStep 2, i.e. eitherWavefrontProxyClientorWavefrontDirectClient.(Optional) Specify a string that represents the source for the reported spans. If you omit the source, the host name is used.Example: Create aWavefrontSpanReporter:importwavefront_opentracing_sdk.reportingfromwavefront_sdkimportWavefrontDirectClient# or# from wavefront_sdk import WavefrontProxyClientwavefront_sender=...# see Step 2wf_span_reporter=wavefront_opentracing_sdk.reporting.WavefrontSpanReporter(client=wavefront_sender,source='wavefront-tracing-example'# optional nondefault source name)# To get failures observed while reporting.total_failures=wf_span_reporter.get_failure_count()Note:After you initialize theWavefrontTracerwith theWavefrontSpanReporter(below), completed spans are automatically reported to Wavefront.
You do not need to start the reporter explicitly.Create a CompositeReporter (Optional)ACompositeReporterenables you to chain aWavefrontSpanReporterto another reporter, such as aConsoleReporter. A console reporter is useful for debugging.fromwavefront_opentracing_sdk.reportingimportCompositeReporterfromwavefront_opentracing_sdk.reportingimportConsoleReporterfromwavefront_opentracing_sdk.reportingimportWavefrontSpanReporterwf_span_reporter=...# Create a console reporter that reports span to stdoutconsole_reporter=ConsoleReporter(source='wavefront-tracing-example')# Instantiate a composite reporter composed of console and WavefrontSpanReporter.composite_reporter=CompositeReporter(wf_span_reporter,console_reporter)4. Create a WavefrontTracerTo create aWavefrontTracer, you pass theApplicationTagsandReporterinstances you created in the previous steps:importwavefront_opentracing_sdkfromwavefront_opentracing_sdk.reportingimportWavefrontSpanReporterfromwavefront_sdk.commonimportApplicationTagsfromwavefront_sdkimportWavefrontDirectClient# or# from wavefront_sdk import WavefrontProxyClientapplication_tags=...# see Step 1 abovewf_span_reporter=...# see Step 3 above# Construct Wavefront opentracing Tracertracer=wavefront_opentracing_sdk.WavefrontTracer(reporter=wf_span_reporter,application_tags=application_tags)Add Custom Span-Level RED metricsOptionally, you can propagate custom span-level tags to RED metrics. SeeCustom Span-Level Tags for RED Metricsfor details.# Construct Wavefront opentracing Tracertracer=wavefront_opentracing_sdk.WavefrontTracer(reporter=wf_span_reporter,application_tags=application_tags,red_metrics_custom_tag_keys={'env','location'})Close the TracerAlways close the tracer before exiting your application to flush all buffered spans to Wavefront.tracer.close()Span LogsYou can instrument your application to emit logs or events with spans, and examine them from theWavefront Tracing UI.Use theOpenTracing Span object's log_kv() methodin your application.Cross Process Context PropagationSee thecontext propagation documentationfor details on propagating span contexts across process boundaries.RED MetricsSee theRED metrics documentationfor details on the out-of-the-box metrics and histograms that are provided.LicenseApache 2.0 License.How to ContributeReach out to us on our publicSlack channel.If you run into any issues, let us know by creating a GitHub issue.