Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Difference between proto and SDK #497

Closed
Lempossible opened this issue Jul 9, 2023 · 2 comments
Closed

Difference between proto and SDK #497

Lempossible opened this issue Jul 9, 2023 · 2 comments

Comments

@Lempossible
Copy link

I want to transform logs into OTel Trace and export it to OTel Exporter myself.

When I used trace.proto file to generate its go file, I found the definition of Span struct is not the same with the one in go.opentelemetry.io/otel/sdk@v1.14.0/trace/span.go.

The Span in trace.pb.go is like this:
`type Span struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields

    ...

TraceId []byte `protobuf:"bytes,1,opt,name=trace_id,json=traceId,proto3" json:"trace_id,omitempty"`

SpanId []byte `protobuf:"bytes,2,opt,name=span_id,json=spanId,proto3" json:"span_id,omitempty"`

ParentSpanId []byte `protobuf:"bytes,4,opt,name=parent_span_id,json=parentSpanId,proto3" json:"parent_span_id,omitempty"`

Name string `protobuf:"bytes,5,opt,name=name,proto3" json:"name,omitempty"`

StartTimeUnixNano uint64 `protobuf:"fixed64,7,opt,name=start_time_unix_nano,json=startTimeUnixNano,proto3" json:"start_time_unix_nano,omitempty"`

EndTimeUnixNano uint64 `protobuf:"fixed64,8,opt,name=end_time_unix_nano,json=endTimeUnixNano,proto3" json:"end_time_unix_nano,omitempty"`

...

}`

while the Span in SDK is like this:
`type recordingSpan struct {
// mu protects the contents of this span.
mu sync.Mutex

// parent holds the parent span of this span as a trace.SpanContext.
parent trace.SpanContext

// spanKind represents the kind of this span as a trace.SpanKind.
spanKind trace.SpanKind

// name is the name of this span.
name string

// startTime is the time at which this span was started.
startTime time.Time

// endTime is the time at which this span was ended. It contains the zero
// value of time.Time until the span is ended.
endTime time.Time

// status is the status of this span.
status Status

// childSpanCount holds the number of child spans created for this span.
childSpanCount int

// spanContext holds the SpanContext of this span.
spanContext trace.SpanContext

// attributes is a collection of user provided key/values. The collection
// is constrained by a configurable maximum held by the parent
// TracerProvider. When additional attributes are added after this maximum
// is reached these attributes the user is attempting to add are dropped.
// This dropped number of attributes is tracked and reported in the
// ReadOnlySpan exported when the span ends.
attributes        []attribute.KeyValue
droppedAttributes int

// events are stored in FIFO queue capped by configured limit.
events evictedQueue

// links are stored in FIFO queue capped by configured limit.
links evictedQueue

// executionTracerTaskEnd ends the execution tracer span.
executionTracerTaskEnd func()

// tracer is the SDK tracer that created this span.
tracer *tracer

}`

For example, the TraceID in SpanContext is [16]byte type.

Will the OTEL exporter take it as correct?

@tigrannajaryan
Copy link
Member

It is not quite clear what exactly you want to do. If you want to generate OTLP data in Go it is probably best to use https://github.com/open-telemetry/opentelemetry-proto-go

The specification in this repo explains what the payloads should look like.

recordingSpan in the SDK is an internal struct that is not intended to be used directly. If you want to know more about it you may want to ask in https://github.com/open-telemetry/opentelemetry-go but there is no expectation that it will be an exact field-by-field match for OTLP's Span ProtoBuf message.

@Lempossible
Copy link
Author

I want to generate OTLP data in go because I can not use SDK to set my own TraceID and SpanID.
But the code generated by protobuf file is much different from codes in SDK. So I was little confused.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants