Skip to content

Commit

Permalink
chore: deprecate use of old columns in traces (#321)
Browse files Browse the repository at this point in the history
* chore: deprecate use of old columns in traces

* chore: add back externalHttpMethod and Url

* chore: update httpRoute according to otel specs
https://opentelemetry.io/docs/specs/semconv/attributes-registry/http/#http-deprecated-attributes

* chore: update httpHost according to otel specs
https://opentelemetry.io/docs/specs/semconv/attributes-registry/http/#http-deprecated-attributes
  • Loading branch information
makeavish committed May 24, 2024
1 parent 3fca134 commit 9d9d74d
Show file tree
Hide file tree
Showing 7 changed files with 259 additions and 50 deletions.
4 changes: 2 additions & 2 deletions config/default-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ extensions:
zpages: {}
exporters:
clickhousetraces:
datasource: tcp://localhost:9000/?database=signoz_traces
datasource: tcp://localhost:9000/signoz_traces
migrations: exporter/clickhousetracesexporter/migrations
retry_on_failure:
enabled: true
Expand All @@ -64,7 +64,7 @@ exporters:
queue_size: 100
num_consumers: 5
clickhousemetricswrite:
endpoint: tcp://localhost:9000/?database=signoz_metrics
endpoint: tcp://localhost:9000/signoz_metrics
resource_to_telemetry_conversion:
enabled: true
prometheus:
Expand Down
23 changes: 4 additions & 19 deletions exporter/clickhousetracesexporter/clickhouse_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,7 @@ func populateOtherDimensions(attributes pcommon.Map, span *Span) {
if err == nil && statusString != 0 {
statusInt = int64(statusString)
}
span.HttpCode = strconv.FormatInt(statusInt, 10)
span.ResponseStatusCode = span.HttpCode
span.ResponseStatusCode = strconv.FormatInt(statusInt, 10)
} else if (k == "http.url" || k == "url.full") && span.Kind == 3 {
value := v.Str()
valueUrl, err := url.Parse(value)
Expand All @@ -198,14 +197,13 @@ func populateOtherDimensions(attributes pcommon.Map, span *Span) {
span.HttpMethod = v.Str()
} else if k == "http.route" {
span.HttpRoute = v.Str()
} else if k == "http.host" {
} else if k == "http.host" || k == "server.address" ||
k == "client.address" || k == "http.request.header.host" {
span.HttpHost = v.Str()
} else if k == "messaging.system" {
span.MsgSystem = v.Str()
} else if k == "messaging.operation" {
span.MsgOperation = v.Str()
} else if k == "component" { // TODO: There was never a "component" attribute in the spec, this was from OpenCensus/OpenTracing
span.Component = v.Str()
} else if k == "db.system" {
span.DBSystem = v.Str()
} else if k == "db.name" {
Expand All @@ -221,14 +219,9 @@ func populateOtherDimensions(attributes pcommon.Map, span *Span) {
if err == nil && statusString != 0 {
statusInt = int64(statusString)
}
span.GRPCCode = strconv.FormatInt(statusInt, 10)
span.ResponseStatusCode = span.GRPCCode
span.ResponseStatusCode = strconv.FormatInt(statusInt, 10)
} else if k == "rpc.method" {
span.RPCMethod = v.Str()
system, found := attributes.Get("rpc.system")
if found && system.Str() == "grpc" {
span.GRPCMethod = v.Str()
}
} else if k == "rpc.service" {
span.RPCService = v.Str()
} else if k == "rpc.system" {
Expand Down Expand Up @@ -371,7 +364,6 @@ func newStructuredSpan(otelSpan ptrace.Span, ServiceName string, resource pcommo
ServiceName: ServiceName,
Kind: int8(otelSpan.Kind()),
StatusCode: int16(otelSpan.Status().Code()),
TagMap: tagMap,
StringTagMap: stringTagMap,
NumberTagMap: numberTagMap,
BoolTagMap: boolTagMap,
Expand Down Expand Up @@ -539,13 +531,6 @@ func extractSpanAttributesFromSpanIndex(span *Span) []SpanAttribute {
DataType: "string",
StringValue: span.ExternalHttpUrl,
})
spanAttributes = append(spanAttributes, SpanAttribute{
Key: "component",
TagType: "tag",
IsColumn: true,
DataType: "string",
StringValue: span.Component,
})
spanAttributes = append(spanAttributes, SpanAttribute{
Key: "dbSystem",
TagType: "tag",
Expand Down
10 changes: 0 additions & 10 deletions exporter/clickhousetracesexporter/schema-signoz.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,9 @@ type Span struct {
HttpMethod string `json:"httpMethod,omitempty"`
HttpHost string `json:"httpHost,omitempty"`
HttpRoute string `json:"httpRoute,omitempty"`
HttpCode string `json:"httpCode,omitempty"`
MsgSystem string `json:"msgSystem,omitempty"`
MsgOperation string `json:"msgOperation,omitempty"`
ExternalHttpUrl string `json:"externalHttpUrl,omitempty"`
Component string `json:"component,omitempty"`
DBSystem string `json:"dbSystem,omitempty"`
DBName string `json:"dbName,omitempty"`
DBOperation string `json:"dbOperation,omitempty"`
Expand All @@ -109,16 +107,13 @@ type Span struct {
ErrorEvent Event `json:"errorEvent,omitempty"`
ErrorID string `json:"errorID,omitempty"`
ErrorGroupID string `json:"errorGroupID,omitempty"`
TagMap map[string]string `json:"tagMap,omitempty"`
StringTagMap map[string]string `json:"stringTagMap,omitempty"`
NumberTagMap map[string]float64 `json:"numberTagMap,omitempty"`
BoolTagMap map[string]bool `json:"boolTagMap,omitempty"`
ResourceTagsMap map[string]string `json:"resourceTagsMap,omitempty"`
HasError bool `json:"hasError,omitempty"`
IsRemote string `json:"isRemote,omitempty"`
TraceModel TraceModel `json:"traceModel,omitempty"`
GRPCCode string `json:"gRPCCode,omitempty"`
GRPCMethod string `json:"gRPCMethod,omitempty"`
RPCSystem string `json:"rpcSystem,omitempty"`
RPCService string `json:"rpcService,omitempty"`
RPCMethod string `json:"rpcMethod,omitempty"`
Expand Down Expand Up @@ -151,17 +146,13 @@ func (s *Span) MarshalLogObject(enc zapcore.ObjectEncoder) error {
enc.AddString("httpMethod", s.HttpMethod)
enc.AddString("httpHost", s.HttpHost)
enc.AddString("httpRoute", s.HttpRoute)
enc.AddString("httpCode", s.HttpCode)
enc.AddString("msgSystem", s.MsgSystem)
enc.AddString("msgOperation", s.MsgOperation)
enc.AddString("externalHttpUrl", s.ExternalHttpUrl)
enc.AddString("component", s.Component)
enc.AddString("dbSystem", s.DBSystem)
enc.AddString("dbName", s.DBName)
enc.AddString("dbOperation", s.DBOperation)
enc.AddString("peerService", s.PeerService)
enc.AddString("gRPCCode", s.GRPCCode)
enc.AddString("gRPCMethod", s.GRPCMethod)
enc.AddString("rpcSystem", s.RPCSystem)
enc.AddString("rpcService", s.RPCService)
enc.AddString("rpcMethod", s.RPCMethod)
Expand All @@ -172,7 +163,6 @@ func (s *Span) MarshalLogObject(enc zapcore.ObjectEncoder) error {
enc.AddObject("errorEvent", &s.ErrorEvent)
enc.AddObject("traceModel", &s.TraceModel)
enc.AddString("event", fmt.Sprintf("%v", s.Events))
enc.AddString("tagMap", fmt.Sprintf("%v", s.TagMap))

return nil
}
Expand Down
5 changes: 0 additions & 5 deletions exporter/clickhousetracesexporter/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,23 +118,18 @@ func (w *SpanWriter) writeIndexBatch(ctx context.Context, batchSpans []*Span) er
span.StatusCode,
span.ExternalHttpMethod,
span.ExternalHttpUrl,
span.Component,
span.DBSystem,
span.DBName,
span.DBOperation,
span.PeerService,
span.Events,
span.HttpMethod,
span.HttpUrl,
span.HttpCode,
span.HttpRoute,
span.HttpHost,
span.MsgSystem,
span.MsgOperation,
span.HasError,
span.TagMap,
span.GRPCMethod,
span.GRPCCode,
span.RPCSystem,
span.RPCService,
span.RPCMethod,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@

DROP TABLE IF EXISTS signoz_traces.durationSortMV ON CLUSTER {{.SIGNOZ_CLUSTER}};
DROP VIEW IF EXISTS signoz_traces.dependency_graph_minutes_db_calls_mv ON CLUSTER {{.SIGNOZ_CLUSTER}};
DROP VIEW IF EXISTS signoz_traces.dependency_graph_minutes_messaging_calls_mv ON CLUSTER {{.SIGNOZ_CLUSTER}};
DROP VIEW IF EXISTS signoz_traces.dependency_graph_minutes_db_calls_mv_v2 ON CLUSTER {{.SIGNOZ_CLUSTER}};
DROP VIEW IF EXISTS signoz_traces.dependency_graph_minutes_messaging_calls_mv_v2 ON CLUSTER {{.SIGNOZ_CLUSTER}};

ALTER TABLE signoz_traces.signoz_index_v2 ON CLUSTER {{.SIGNOZ_CLUSTER}}
ADD COLUMN IF NOT EXISTS tagMap Map(LowCardinality(String), String) CODEC(ZSTD(1)),
ADD COLUMN IF NOT EXISTS gRPCCode LowCardinality(String) CODEC(ZSTD(1)),
ADD COLUMN IF NOT EXISTS gRPCMethod LowCardinality(String) CODEC(ZSTD(1)),
ADD COLUMN IF NOT EXISTS httpCode LowCardinality(String) CODEC(ZSTD(1)),
ADD COLUMN IF NOT EXISTS component LowCardinality(String) CODEC(ZSTD(1));

ALTER TABLE signoz_traces.distributed_signoz_index_v2 ON CLUSTER {{.SIGNOZ_CLUSTER}}
ADD COLUMN IF NOT EXISTS tagMap Map(LowCardinality(String), String) CODEC(ZSTD(1)),
ADD COLUMN IF NOT EXISTS gRPCCode LowCardinality(String) CODEC(ZSTD(1)),
ADD COLUMN IF NOT EXISTS gRPCMethod LowCardinality(String) CODEC(ZSTD(1)),
ADD COLUMN IF NOT EXISTS httpCode LowCardinality(String) CODEC(ZSTD(1)),
ADD COLUMN IF NOT EXISTS component LowCardinality(String) CODEC(ZSTD(1));

ALTER TABLE signoz_traces.durationSort ON CLUSTER {{.SIGNOZ_CLUSTER}}
ADD COLUMN IF NOT EXISTS tagMap Map(LowCardinality(String), String) CODEC(ZSTD(1)),
ADD COLUMN IF NOT EXISTS gRPCCode LowCardinality(String) CODEC(ZSTD(1)),
ADD COLUMN IF NOT EXISTS gRPCMethod LowCardinality(String) CODEC(ZSTD(1)),
ADD COLUMN IF NOT EXISTS httpCode LowCardinality(String) CODEC(ZSTD(1)),
ADD COLUMN IF NOT EXISTS component LowCardinality(String) CODEC(ZSTD(1));

ALTER TABLE signoz_traces.distributed_durationSort ON CLUSTER {{.SIGNOZ_CLUSTER}}
ADD COLUMN IF NOT EXISTS tagMap Map(LowCardinality(String), String) CODEC(ZSTD(1)),
ADD COLUMN IF NOT EXISTS gRPCCode LowCardinality(String) CODEC(ZSTD(1)),
ADD COLUMN IF NOT EXISTS gRPCMethod LowCardinality(String) CODEC(ZSTD(1)),
ADD COLUMN IF NOT EXISTS httpCode LowCardinality(String) CODEC(ZSTD(1)),
ADD COLUMN IF NOT EXISTS component LowCardinality(String) CODEC(ZSTD(1));

CREATE MATERIALIZED VIEW IF NOT EXISTS signoz_traces.durationSortMV ON CLUSTER {{.SIGNOZ_CLUSTER}}
TO signoz_traces.durationSort
AS SELECT
timestamp,
traceID,
spanID,
parentSpanID,
serviceName,
name,
kind,
durationNano,
statusCode,
component,
httpMethod,
httpUrl,
httpCode,
httpRoute,
httpHost,
gRPCCode,
gRPCMethod,
hasError,
tagMap,
rpcSystem,
rpcService,
rpcMethod,
responseStatusCode,
stringTagMap,
numberTagMap,
boolTagMap,
isRemote
FROM signoz_traces.signoz_index_v2
ORDER BY durationNano, timestamp;

CREATE MATERIALIZED VIEW IF NOT EXISTS signoz_traces.dependency_graph_minutes_db_calls_mv ON CLUSTER {{.SIGNOZ_CLUSTER}}
TO signoz_traces.dependency_graph_minutes AS
SELECT
serviceName as src,
tagMap['db.system'] as dest,
quantilesState(0.5, 0.75, 0.9, 0.95, 0.99)(toFloat64(durationNano)) as duration_quantiles_state,
countIf(statusCode=2) as error_count,
count(*) as total_count,
toStartOfMinute(timestamp) as timestamp
FROM signoz_traces.signoz_index_v2
WHERE dest != '' and kind != 2
GROUP BY timestamp, src, dest;

CREATE MATERIALIZED VIEW IF NOT EXISTS signoz_traces.dependency_graph_minutes_messaging_calls_mv ON CLUSTER {{.SIGNOZ_CLUSTER}}
TO signoz_traces.dependency_graph_minutes AS
SELECT
serviceName as src,
tagMap[messaging.system] as dest,
quantilesState(0.5, 0.75, 0.9, 0.95, 0.99)(toFloat64(durationNano)) as duration_quantiles_state,
countIf(statusCode=2) as error_count,
count(*) as total_count,
toStartOfMinute(timestamp) as timestamp
FROM signoz_traces.signoz_index_v2
WHERE dest != '' and kind != 2
GROUP BY timestamp, src, dest;

CREATE MATERIALIZED VIEW IF NOT EXISTS signoz_traces.dependency_graph_minutes_db_calls_mv_v2 ON CLUSTER {{.SIGNOZ_CLUSTER}}
TO signoz_traces.dependency_graph_minutes_v2 AS
SELECT
serviceName as src,
tagMap['db.system'] as dest,
quantilesState(0.5, 0.75, 0.9, 0.95, 0.99)(toFloat64(durationNano)) as duration_quantiles_state,
countIf(statusCode=2) as error_count,
count(*) as total_count,
toStartOfMinute(timestamp) as timestamp,
resourceTagsMap['deployment.environment'] as deployment_environment,
resourceTagsMap['k8s.cluster.name'] as k8s_cluster_name,
resourceTagsMap['k8s.namespace.name'] as k8s_namespace_name
FROM signoz_traces.signoz_index_v2
WHERE dest != '' and kind != 2
GROUP BY timestamp, src, dest, deployment_environment, k8s_cluster_name, k8s_namespace_name;

CREATE MATERIALIZED VIEW IF NOT EXISTS signoz_traces.dependency_graph_minutes_messaging_calls_mv_v2 ON CLUSTER {{.SIGNOZ_CLUSTER}}
TO signoz_traces.dependency_graph_minutes_v2 AS
SELECT
serviceName as src,
tagMap[messaging.system] as dest,
quantilesState(0.5, 0.75, 0.9, 0.95, 0.99)(toFloat64(durationNano)) as duration_quantiles_state,
countIf(statusCode=2) as error_count,
count(*) as total_count,
toStartOfMinute(timestamp) as timestamp,
resourceTagsMap['deployment.environment'] as deployment_environment,
resourceTagsMap['k8s.cluster.name'] as k8s_cluster_name,
resourceTagsMap['k8s.namespace.name'] as k8s_namespace_name
FROM signoz_traces.signoz_index_v2
WHERE dest != '' and kind != 2
GROUP BY timestamp, src, dest, deployment_environment, k8s_cluster_name, k8s_namespace_name;
Loading

0 comments on commit 9d9d74d

Please sign in to comment.