Skip to content

Commit

Permalink
feat: add low_cardinal_exception_grouping config (#92)
Browse files Browse the repository at this point in the history
  • Loading branch information
makeavish committed Feb 10, 2023
1 parent 1647abe commit 86419af
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
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"`
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

0 comments on commit 86419af

Please sign in to comment.