OpenTracing was a set of vendor-neutral APIs and instrumentation standards for distributed tracing, aimed at providing insights into the flow of requests across complex, microservices-based systems. Though now an archived project, its legacy lives on as a foundational element in the development of the more comprehensive OpenTelemetry project.
* **Span:** Represents a single unit of work within a trace, such as a database query or an HTTP request. Spans can be nested to represent hierarchical relationships between operations. * **Trace:** A collection of spans that captures the entire path of a request through a distributed system.
1. **Creating a Span (Java):**
```java import io.opentracing.Span; import io.opentracing.Tracer;
Tracer tracer = …; // Obtain a Tracer instance
Span span = tracer.buildSpan(“my-operation”).start(); try {
// Your application logic here...} finally {
span.finish();} ```
2. **Adding Tags and Logs (Python):**
```python import opentracing
tracer = …
span = tracer.start_span(“my-operation”) span.set_tag(“user_id”, 12345) span.log_kv({“event”: “database_query”, “query”: “SELECT * FROM users”}) span.finish() ```
3. **Context Propagation (HTTP Headers):**
```java import io.opentracing.propagation.Format; import io.opentracing.propagation.TextMapInjectAdapter;
Tracer tracer = …; Span span = …;
HttpHeaders headers = new HttpHeaders(); tracer.inject(span.context(), Format.Builtin.HTTP_HEADERS, new TextMapInjectAdapter(headers));
// Send the HTTP request with the injected headers ```
These examples demonstrate basic OpenTracing concepts, but the actual implementations might vary depending on the specific language and tracing backend used.
OpenTracing has been archived and is no longer actively developed. Its concepts and APIs have been merged into OpenTelemetry, a more comprehensive observability framework that includes metrics and logs in addition to traces. If you're starting a new project or considering adding distributed tracing to your application, it's recommended to use OpenTelemetry instead of OpenTracing.