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

writer: new option to log rejected spans #1922

Merged
merged 4 commits into from
Sep 22, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/config-schema.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ The **nested** `writer` config object has the following fields:
| `logDatapoints` | no | bool | If the log level is set to `debug` and this is true, all datapoints generated by the agent will be logged. (**default:** `false`) |
| `logEvents` | no | bool | The analogue of `logDatapoints` for events. (**default:** `false`) |
| `logTraceSpans` | no | bool | The analogue of `logDatapoints` for trace spans. (**default:** `false`) |
| `logTraceSpansFailedToShip` | no | bool | If `true`, traces and spans which weren't successfully received by the backend, will be logged as json (**default:** `false`) |
| `logDimensionUpdates` | no | bool | If `true`, dimension updates will be logged at the INFO level. (**default:** `false`) |
| `logDroppedDatapoints` | no | bool | If true, and the log level is `debug`, filtered out datapoints will be logged. (**default:** `false`) |
| `addGlobalDimensionsAsSpanTags` | no | bool | If true, the dimensions specified in the top-level `globalDimensions` configuration will be added to the tag set of all spans that are emitted by the writer. If this is false, only the "host id" dimensions such as `host`, `AwsUniqueId`, etc. are added to the span tags. (**default:** `false`) |
Expand Down Expand Up @@ -428,6 +429,7 @@ where applicable:
logDatapoints: false
logEvents: false
logTraceSpans: false
logTraceSpansFailedToShip: false
logDimensionUpdates: false
logDroppedDatapoints: false
addGlobalDimensionsAsSpanTags: false
Expand Down
3 changes: 3 additions & 0 deletions pkg/core/config/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ type WriterConfig struct {
LogEvents bool `yaml:"logEvents"`
// The analogue of `logDatapoints` for trace spans.
LogTraceSpans bool `yaml:"logTraceSpans"`
// If `true`, traces and spans which weren't successfully received by the
// backend, will be logged as json
LogTraceSpansFailedToShip bool `yaml:"logTraceSpansFailedToShip"`
// If `true`, dimension updates will be logged at the INFO level.
LogDimensionUpdates bool `yaml:"logDimensionUpdates"`
// If true, and the log level is `debug`, filtered out datapoints will be
Expand Down
18 changes: 15 additions & 3 deletions pkg/core/writer/signalfx/spans.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,21 @@ func (sw *Writer) sendSpans(ctx context.Context, spans []*trace.Span) error {
// This sends synchonously
err := sw.client.AddSpans(context.Background(), spans)
if err != nil {
log.WithFields(log.Fields{
"error": err,
}).Error("Error shipping spans to SignalFx")
var meta log.Fields
if sw.conf.LogTraceSpansFailedToShip {
jsonEncodedSpans, _ := json.Marshal(spans)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

err should be checked or this can panic. Also if we failed to ship them it is possible json.Marshal could fail as well.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think jsonEncodedSpans would be nil if there were an err so payload below would just show nil. A json marshal error is pretty hard to imagine though since we aren't using generic data structures in the spans, just a well-defined span format that we know serializes fine.

meta = log.Fields{
"error": err,
"payload": string(jsonEncodedSpans),
}
} else {
meta = log.Fields{
"error": err,
}
}

log.WithFields(meta).Error("Error shipping spans to SignalFx")

// If there is an error sending spans then just forget about them.
return err
}
Expand Down
8 changes: 8 additions & 0 deletions selfdescribe.json
Original file line number Diff line number Diff line change
Expand Up @@ -58322,6 +58322,14 @@
"type": "bool",
"elementKind": ""
},
{
"yamlName": "logTraceSpansFailedToShip",
"doc": "If `true`, traces and spans which weren't successfully received by the backend, will be logged as json",
"default": false,
"required": false,
"type": "bool",
"elementKind": ""
},
{
"yamlName": "logDimensionUpdates",
"doc": "If `true`, dimension updates will be logged at the INFO level.",
Expand Down