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

feat: add low_cardinal_exception_grouping config #92

Merged
merged 1 commit into from
Feb 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 18 additions & 7 deletions exporter/clickhousetracesexporter/clickhouse_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,19 @@ func newExporter(cfg component.ExporterConfig, logger *zap.Logger) (*storage, er
return nil, err
}

storage := storage{Writer: spanWriter, usageCollector: collector}
storage := storage{Writer: spanWriter, usageCollector: collector, config: storageConfig{lowCardinalExceptionGrouping: configClickHouse.LowCardinalExceptionGrouping}}

return &storage, nil
}

type storage struct {
Writer Writer
usageCollector *usage.UsageCollector
config storageConfig
}

type storageConfig struct {
lowCardinalExceptionGrouping bool
}

func makeJaegerProtoReferences(
Expand Down Expand Up @@ -212,7 +217,7 @@ func populateOtherDimensions(attributes pcommon.Map, span *Span) {

}

func populateEvents(events ptrace.SpanEventSlice, span *Span) {
func populateEvents(events ptrace.SpanEventSlice, span *Span, lowCardinalExceptionGrouping bool) {
for i := 0; i < events.Len(); i++ {
event := Event{}
event.Name = events.At(i).Name()
Expand All @@ -229,8 +234,14 @@ func populateEvents(events ptrace.SpanEventSlice, span *Span) {
uuidWithHyphen := uuid.New()
uuid := strings.Replace(uuidWithHyphen.String(), "-", "", -1)
span.ErrorID = uuid
hmd5 := md5.Sum([]byte(span.ServiceName + span.ErrorEvent.AttributeMap["exception.type"] + span.ErrorEvent.AttributeMap["exception.message"]))
span.ErrorGroupID = fmt.Sprintf("%x", hmd5)
var hash [16]byte
if lowCardinalExceptionGrouping {
hash = md5.Sum([]byte(span.ServiceName + span.ErrorEvent.AttributeMap["exception.type"]))
} else {
hash = md5.Sum([]byte(span.ServiceName + span.ErrorEvent.AttributeMap["exception.type"] + span.ErrorEvent.AttributeMap["exception.message"]))

}
span.ErrorGroupID = fmt.Sprintf("%x", hash)
}
stringEvent, _ := json.Marshal(event)
span.Events = append(span.Events, string(stringEvent))
Expand All @@ -242,7 +253,7 @@ func populateTraceModel(span *Span) {
span.TraceModel.HasError = span.HasError
}

func newStructuredSpan(otelSpan ptrace.Span, ServiceName string, resource pcommon.Resource) *Span {
func newStructuredSpan(otelSpan ptrace.Span, ServiceName string, resource pcommon.Resource, config storageConfig) *Span {
durationNano := uint64(otelSpan.EndTimestamp() - otelSpan.StartTimestamp())

attributes := otelSpan.Attributes()
Expand Down Expand Up @@ -323,7 +334,7 @@ func newStructuredSpan(otelSpan ptrace.Span, ServiceName string, resource pcommo
span.HasError = true
}
populateOtherDimensions(attributes, span)
populateEvents(otelSpan.Events(), span)
populateEvents(otelSpan.Events(), span, config.lowCardinalExceptionGrouping)
populateTraceModel(span)

return span
Expand All @@ -349,7 +360,7 @@ func (s *storage) pushTraceData(ctx context.Context, td ptrace.Traces) error {
for k := 0; k < spans.Len(); k++ {
span := spans.At(k)
// traceID := hex.EncodeToString(span.TraceID())
structuredSpan := newStructuredSpan(span, serviceName, rs.Resource())
structuredSpan := newStructuredSpan(span, serviceName, rs.Resource(), s.config)
err := s.Writer.WriteSpan(structuredSpan)
if err != nil {
zap.S().Error("Error in writing spans to clickhouse: ", err)
Expand Down
6 changes: 4 additions & 2 deletions exporter/clickhousetracesexporter/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,17 @@ import (
"go.opentelemetry.io/collector/config"
)

// Config defines configuration for logging exporter.
// Config defines configuration for tracing exporter.
type Config struct {
config.ExporterSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct

Options `mapstructure:",squash"`
Datasource string `mapstructure:"datasource"`
Migrations string `mapstructure:"migrations"`
// Docker Multi Node Cluster is a flag to enable the docker multi node cluster. Default is false.
DockerMultiNodeCluster bool `mapstructure:"docker_multi_node_cluster" default:"false"`
makeavish marked this conversation as resolved.
Show resolved Hide resolved
DockerMultiNodeCluster bool `mapstructure:"docker_multi_node_cluster"`
// LowCardinalExceptionGrouping is a flag to enable exception grouping by serviceName + exceptionType. Default is false.
LowCardinalExceptionGrouping bool `mapstructure:"low_cardinal_exception_grouping"`
}

var _ component.ExporterConfig = (*Config)(nil)
Expand Down