-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
logsdata_to_adx.go
46 lines (39 loc) · 2.13 KB
/
logsdata_to_adx.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
package azuredataexplorerexporter // import "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/azuredataexplorerexporter"
import (
"time"
"go.opentelemetry.io/collector/pdata/pcommon"
"go.opentelemetry.io/collector/pdata/plog"
"go.uber.org/zap"
"github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal/traceutil"
)
type AdxLog struct {
Timestamp string // The timestamp of the occurrence. Formatted into string as RFC3339Nano
ObservedTimestamp string // The timestamp of logs observed in opentelemetry collector. Formatted into string as RFC3339Nano
TraceID string // TraceId associated to the log
SpanID string // SpanId associated to the log
SeverityText string // The severity level of the log
SeverityNumber int32 // The severity number associated to the log
Body string // The body/Text of the log
ResourceAttributes map[string]any // JSON Resource attributes that can then be parsed.
LogsAttributes map[string]any // JSON attributes that can then be parsed.
}
// Convert the plog to the type ADXLog, this matches the scheme in the Log table in the database
func mapToAdxLog(resource pcommon.Resource, scope pcommon.InstrumentationScope, logData plog.LogRecord, _ *zap.Logger) *AdxLog {
logAttrib := logData.Attributes().AsRaw()
clonedLogAttrib := cloneMap(logAttrib)
copyMap(clonedLogAttrib, getScopeMap(scope))
adxLog := &AdxLog{
Timestamp: logData.Timestamp().AsTime().Format(time.RFC3339Nano),
ObservedTimestamp: logData.ObservedTimestamp().AsTime().Format(time.RFC3339Nano),
TraceID: traceutil.TraceIDToHexOrEmptyString(logData.TraceID()),
SpanID: traceutil.SpanIDToHexOrEmptyString(logData.SpanID()),
SeverityText: logData.SeverityText(),
SeverityNumber: int32(logData.SeverityNumber()),
Body: logData.Body().AsString(),
ResourceAttributes: resource.Attributes().AsRaw(),
LogsAttributes: clonedLogAttrib,
}
return adxLog
}