Skip to content

Commit

Permalink
[exporter/azuredataexplorer] Status Attributes added to exported trac…
Browse files Browse the repository at this point in the history
…es (open-telemetry#26682)

**Description:** <Describe what has changed.>
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
Added an optional column in the exported trace data to store the status
code and message as a dynamic field.


**Link to tracking Issue:** <Issue number if applicable>

[open-telemetry#26496](open-telemetry#26496)

**Testing:** <Describe what testing was performed and which tests were
added.>
Performed E2E ingestion tests and added Test Cases for new fields.

**Documentation:** <Describe the documentation added.>

---------

Co-authored-by: Ramachandran A G <[email protected]>
Co-authored-by: Ramachandran A G <[email protected]>
  • Loading branch information
3 people authored and jmsnll committed Nov 12, 2023
1 parent 44dc5ce commit dc99e20
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 4 deletions.
27 changes: 27 additions & 0 deletions .chloggen/bugfix_26496105-StatusMessage.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: enhancement

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: azuredataexplorerexporter

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Added an optional column in the exported trace data to store the status code and message as a dynamic field.

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [26496]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:

# If your change doesn't affect end users or the exported elements of any package,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: [user]
7 changes: 6 additions & 1 deletion exporter/azuredataexplorerexporter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ This exporter maps OpenTelemetry [trace](https://opentelemetry.io/docs/referenc
| SpanId | A valid span identifier is an 8-byte array with at least one non-zero byte. |
| ParentId | A parent spanId, for the current span |
| SpanName | The span name |
| SpanStatus | [Status](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/api.md#set-status) of the Span. |
| SpanStatus | [Status Code](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/api.md#set-status) of the Span. |
| SpanStatusMessage | [Status Message](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/api.md#set-status) of the Span |
| SpanKind | [SpanKind](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/api.md#spankind) describes the relationship between the Span, its parents, and its children in a Trace |
| StartTime | A start timestamp |
| EndTime | An end timestamp |
Expand Down Expand Up @@ -140,6 +141,10 @@ The following tables need to be created in the database specified in the configu

.create-merge table <Traces-Table-Name> (TraceID:string, SpanID:string, ParentID:string, SpanName:string, SpanStatus:string, SpanKind:string, StartTime:datetime, EndTime:datetime, ResourceAttributes:dynamic, TraceAttributes:dynamic, Events:dynamic, Links:dynamic)

// This is an optional column to store the status code and message as a dynamic field. This augments the status field with Status code and status message

.alter-merge table <Traces-Table-Name> (SpanStatusMessage:string)

//Enable streaming ingestion( for managed streaming) for the created tables using
.alter table <Table-Name> policy streamingingestion enable

Expand Down
2 changes: 2 additions & 0 deletions exporter/azuredataexplorerexporter/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ func TestCreateTracesExporterE2E(t *testing.T) {
assert.Equal(t, "", recs[i].ParentID)
assert.Equal(t, spanName, recs[i].SpanName)
assert.Equal(t, "STATUS_CODE_UNSET", recs[i].SpanStatus)
assert.Equal(t, "STATUS_MESSAGE", recs[i].SpanStatusMessage)
assert.Equal(t, "SPAN_KIND_UNSPECIFIED", recs[i].SpanKind)
assert.Equal(t, epochTimeString, recs[i].StartTime)
assert.Equal(t, epochTimeString, recs[i].EndTime)
Expand Down Expand Up @@ -258,6 +259,7 @@ func createTraces() (ptrace.Traces, string, map[string]interface{}) {
td := ptrace.NewTraces()
span := td.ResourceSpans().AppendEmpty().ScopeSpans().AppendEmpty().Spans().AppendEmpty()
span.SetName(spanName)
span.Status().SetMessage("STATUS_MESSAGE")
attrs := map[string]interface{}{
"k0": "v0",
"k1": "v1",
Expand Down
9 changes: 8 additions & 1 deletion exporter/azuredataexplorerexporter/tracesdata_to_adx.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ type AdxTrace struct {
SpanID string // SpanID associated to the Trace
ParentID string // ParentID associated to the Trace
SpanName string // The SpanName of the Trace
SpanStatus string // The SpanStatus associated to the Trace
SpanStatus string // The SpanStatus Code associated to the Trace
SpanStatusMessage string // The SpanStatusMessage associated to the Trace
SpanKind string // The SpanKind of the Trace
StartTime string // The start time of the occurrence. Formatted into string as RFC3339Nano
EndTime string // The end time of the occurrence. Formatted into string as RFC3339Nano
Expand All @@ -40,6 +41,11 @@ type Link struct {
SpanLinkAttributes map[string]interface{}
}

type Status struct {
Code string
Message string
}

func mapToAdxTrace(resource pcommon.Resource, scope pcommon.InstrumentationScope, spanData ptrace.Span) *AdxTrace {

traceAttrib := spanData.Attributes().AsRaw()
Expand All @@ -52,6 +58,7 @@ func mapToAdxTrace(resource pcommon.Resource, scope pcommon.InstrumentationScope
ParentID: traceutil.SpanIDToHexOrEmptyString(spanData.ParentSpanID()),
SpanName: spanData.Name(),
SpanStatus: traceutil.StatusCodeStr(spanData.Status().Code()),
SpanStatusMessage: spanData.Status().Message(),
SpanKind: traceutil.SpanKindStr(spanData.Kind()),
StartTime: spanData.StartTimestamp().AsTime().Format(time.RFC3339Nano),
EndTime: spanData.EndTimestamp().AsTime().Format(time.RFC3339Nano),
Expand Down
55 changes: 53 additions & 2 deletions exporter/azuredataexplorerexporter/tracesdata_to_adx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ func Test_mapToAdxTrace(t *testing.T) {
{
name: "valid",
spanDatafn: func() ptrace.Span {

span := ptrace.NewSpan()
span.SetName("spanname")
span.Status().SetCode(ptrace.StatusCodeUnset)
Expand Down Expand Up @@ -84,7 +83,6 @@ func Test_mapToAdxTrace(t *testing.T) {
}, {
name: "with_events_links",
spanDatafn: func() ptrace.Span {

span := ptrace.NewSpan()
span.SetName("spanname")
span.Status().SetCode(ptrace.StatusCodeUnset)
Expand Down Expand Up @@ -134,6 +132,59 @@ func Test_mapToAdxTrace(t *testing.T) {
}},
},
},
{
name: "with_status_message_for_error",
spanDatafn: func() ptrace.Span {
span := ptrace.NewSpan()
span.SetName("spanname-status-message")
span.Status().SetCode(ptrace.StatusCodeError)
span.Status().SetMessage("An error occurred")
span.SetTraceID(pcommon.TraceID(traceID))
span.SetSpanID(pcommon.SpanID(spanID))
span.SetKind(ptrace.SpanKindServer)
span.SetStartTimestamp(ts)
span.SetEndTimestamp(ts)
span.Attributes().PutStr("traceAttribKey", "traceAttribVal")
event := span.Events().AppendEmpty()
event.SetName("eventName")
event.SetTimestamp(ts)
event.Attributes().PutStr("eventkey", "eventvalue")

link := span.Links().AppendEmpty()
link.SetSpanID(pcommon.SpanID(spanID))
link.SetTraceID(pcommon.TraceID(traceID))
link.TraceState().FromRaw("")
return span
},
resourceFn: newDummyResource,
insScopeFn: newScopeWithData,
expectedAdxTrace: &AdxTrace{
TraceID: "00000000000000000000000000000064",
SpanID: "0000000000000032",
ParentID: "",
SpanName: "spanname-status-message",
SpanStatus: "STATUS_CODE_ERROR",
SpanStatusMessage: "An error occurred",
SpanKind: "SPAN_KIND_SERVER",
StartTime: tstr,
EndTime: tstr,
ResourceAttributes: tmap,
TraceAttributes: newMapFromAttr(`{"traceAttribKey":"traceAttribVal", "scope.name":"testscope", "scope.version":"1.0"}`),
Events: []*Event{
{
EventName: "eventName",
EventAttributes: newMapFromAttr(`{"eventkey": "eventvalue"}`),
Timestamp: tstr,
},
},
Links: []*Link{{
TraceID: "00000000000000000000000000000064",
SpanID: "0000000000000032",
TraceState: "",
SpanLinkAttributes: newMapFromAttr(`{}`),
}},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit dc99e20

Please sign in to comment.