The LogContext contains information required to trace distributed transactions or requests made to a distributed system. Such a trace may produce multiple log messages in one OPC UA Application and/or multiple log messages across multiple OPC UA Applications.

The TraceId is a unique identifier for a trace. Once assigned it never changes for that trace. If log messages for a given trace are across applications, they have the same TraceId.

A span represents a unit of work or operation. Spans are the building blocks of traces. A span is local to an OPC UA Application. The SpanId is a unique identifier assigned by an OPC UA Application for a local span in a trace. Spans can be nested. The ParentSpanId provides the reference to the parent span. The ParentSpanId is used to build a tree of spans inside a trace. If a nested span is created, the SpanId of the parent is used as ParentSpanId in the new child span.

At the very start (the root span) there is no ParentSpanId, only a new SpanId. This would be the base of a tree. See C.1 for additional discussion on SpanId and ParentSpanId.

The SpanContextDataType Structure is defined in Table 7. It defines a TraceId and SpanId. This Structure can be passed between Clients and Servers (see 5.5.4).

Table 7 – SpanContextDataType

Name

Type

Description

SpanContextDataType

Structure

Subtype of Structure defined in OPC 10000-5

TraceId

0:Guid

A unique identifier assigned to a trace.

SpanId

0:UInt64

Identifier for a span in a trace. 0 is an invalid value for a SpanId. The value shall be unique within a ParentSpanId within an Application.

The SpanContextDataType representation in the AddressSpace is formally defined in Table 8

Table 8 – SpanContextDataType definition

Attribute

Value

BrowseName

SpanContextDataType

IsAbstract

False

References

NodeClass

BrowseName

DataType

TypeDefinition

Other

Subtype of the 0:Structure defined in OPC 10000-5

ConformanceUnits

LogObject TraceContext

The TraceContextDataType Structure is defined in Table 9. This structure is a subtype of the SpanContextDataType and is used in the LogRecord. It extends the SpanContextDataType Structure adding two additional fields. The ParentSpanId (together with the SpanId) allows for the creation of a tree of related Log Records. The ParentIdentifier can be used to provide context information related to the parent.

Table 9 – TraceContextDataType

Name

Type

Description

TraceContextDataType

Structure

Subtype of SpanContextDataType defined in 5.5.2

ParentSpanId

0:UInt64

The identifier of the parent span. The value is 0 for a root span.

ParentIdentifier

0:String

If the parent span is from another OPC UA Application, the ParentIdentifier contains the ApplicationUri of the other OPC UA Application.

If the parent span is an internal span, the ParentIdentifier shall be null or empty.

If the ParentSpanId is 0, the ParentIdentifier shall be null or empty.

The TraceContextDataType representation in the AddressSpace is formally defined in Table 10.

Table 10 – TraceContextDataType definition

Attribute

Value

BrowseName

TraceContextDataType

IsAbstract

False

References

NodeClass

BrowseName

DataType

TypeDefinition

Other

Subtype of the SpanContextDataType defined in 5.5.2

ConformanceUnits

LogObject TraceContext

If the Server is to be part of a Client trace, the Client passes the SpanContextDataType structure to a Server.

The SpanContextDataType Structure, defined in Table 7, is passed in the RequestHeader of any OPC UA Service call. The SpanContextDataType is transported with the AdditionalParametersType in the AdditionalHeader field of the RequestHeader (see OPC 10000-4). The Key for the parameter is “SpanContext and the Value is the SpanContextDataType Structure.

If a Server receives the optional AdditionalHeader, it uses the provided SpanConextDataType Structure when generating any LogRecords that are generated related to the Service invocation that provided the AdditionalHeader. It is possible that lower level functionality that is invoked as part of the Service call, may not have access to the provided AdditionalHeader, in which case it maybe omitted.

Inside the Server, the SpanId from the RequestHeader is used as ParentId for the LogContext structure defined in Table 9.