Choose “Star standard”, heavy dry goods, the first time delivery! [If you think this article is helpful to you, welcome to follow, like and forward]


preface


Company recently there was a bug, where is the problem has not been found out, is an interface to invoke two main application of the log output is no problem, and in the entire request link is longer, positioning positioning the problem alone for a long time, efficiency is low, so ‘, the strong request of the moon, and prepare in every link tracking service access distributed framework.

Why do we need distributed link tracing



In the existing service system architecture, the increase in the number of services, service and the complexity of the relationship between a request issued before may after dealing with the N service returns a response, so, when the bugs, developers can only rely on the log screen one by one, low efficiency of terrible, so the distributed link tracking became you the optimal solution.

Of course, this is only one of the factors, distributed link tracing can solve the problem of service links, it can also do:

  • 1: Queries the IP address of each application
  • 2: how long does each interface take to respond and what is the network overhead
  • 3: indicates the execution time of the application and whether the application is successfully executed
  • 4: How long did it take
  • 5: What does each interface return and what is requested?
  • 6: How many times does each application call the database? .

trace_ID


So how do you determine what services a request has passed through from initiation to completion?

You must have thought of a unique Id to implement, that is, I create a global unique Id when the request is initiated, and then carry this Id with the subsequent request, so that I can use this unique Id to determine which services have been passed.

The diagram below:


We can clearly see from the trace_ID that A request from A has passed through those services

span_ID


Now we know all the called services, but we will also find A problem, we find that when service A calls service B, B will call two services, one is service C, one is service B, so how to determine the sequence?


Yes, it is to introduce a span_ID to determine the sequence of service invocation. As shown in the figure, the invocation link can be determined as

Service A-> Service B-> Service C-> Service D-> Service E-> Service F

parent_ID


Parent_ID = “parent_ID”; parent_ID = “parent_ID”


For example, if we see that the parent_ID of service C is 2, then we know that service span_ID 2 calls service C, that is, service B calls service C

What is OpenTracing


In order to avoid fragmentation and promote interoperability, the community formed a standardization organization called OpenTracing, which developed some API specifications for link tracing and provided some frameworks and libraries to implement the API specifications. And it’s an independent, open project that’s now part of the Cloud Native Computing Foundation (CNCF). Any organization or individual can contribute libraries/frameworks that conform to the API specification.


It is important to note that the frameworks and libraries provided by OpenTracing do not do analysis, so it is not a complete link system.

OpenTracing aims to standardize Trace data structures and formats. Its purpose is to:

  • Trace clients developed in different languages can interoperate with OpenTracing compatible monitoring backends as long as they follow the OpenTracing standard.
  • Tracing monitors interoperability of backends. As long as the OpenTracing standard is followed, enterprises can replace specific Tracing monitoring backends as needed, such as from Zipkin to Skywalking.

Data model of distributed link tracking system:


In the OpenTracing specification, there are three key, related relational types: Tracer, Span, and SpanContext.

Traces: Requests are generated together, passed through multiple modules (functions, systems, or both), and returned at the same time. The entire request is traced based on call times and relationships.

Span is the most basic unit of trace and generally represents an independent unit of work in a distributed system. A Span consists of the following parts:

  • Operation name: Display, filter, and aggregate
  • Start and End Timestamps: Used to calculate time Tags composed of key-values: used to add some time-independent information (optional) Logs composed of key-values and containing time stamps: Used to add some time-dependent information (optional)
  • SpanContext. It generally contains two parts of data:
    • (1) Span status data, such as traceID and spanID
    • (2) Baggage Items. Baggage is a common way of transferring data across processes and services provided by link tracing in the key-value format.
  • Trace is a directed acyclic graph composed of several spans. Each node in the graph is span, and the edge connecting nodes is called References. Each trace has a unique identifier traceID, and each SPAN has a unique identifier spanID. TraceID for all spans in a link are the same, but SPANids vary. A typical span call diagram in a link is as follows:

The corresponding time dimension is:

There are two possible relationships between a trace span:

  • ChildOf: an operation can be a ChildOf another operation. In a ChildOf reference, the parent operation depends to some extent on the child operation, so to speak, until the child operation completes.
  • FollowsFrom: The child Span is invoked by the parent Span, but the parent Span does not depend on the child Span. In this case, the child operation is only triggered by the parent operation. Operations that conform to this relationship can be further divided into many subtypes.

The last concept that needs to be introduced is active Span. A thread can contain multiple spans, but only one span can be in working state at a time. This span is called ActiveSpan. Span can have several states:

  • Started
  • Not Finished
  • Not “active”
  • The status of Active Span is managed by ScopeManager, but implementation is up to the developer. Additionally, OpenTracing defines Inject and Extract interfaces to simplify SpanContext delivery across processes.

conclusion


1: Distributed link tracing is to restore a complete request link and clearly trace the information of each service.

2. Since there are various ways to implement distributed link tracing, OpenTracing organization customized a specification and defined a standard. The most important three indicators are Tracer, Span and SpanContext.

https://niyanchun.com/opentracing-introduction.html the shoulders of giants

If you think the article is good, you can click a “like” and read it. Everyone’s support is the biggest motivation for me. You can also follow my official account and my personal wechat account of Moon to make a casual acquaintance