Skip to content

Commit

Permalink
emitBatchOverhead should only be used for splitting spans into batches (
Browse files Browse the repository at this point in the history
  • Loading branch information
ken8203 committed Jan 14, 2022
1 parent 73edf3d commit baa4427
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Expand Up @@ -15,7 +15,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

### Changed

- Jaeger exporter takes into additional 70 bytes overhead into consideration when sending UDP packets (#2489)
- Jaeger exporter takes into additional 70 bytes overhead into consideration when sending UDP packets (#2489, #2512)

### Deprecated

Expand Down
11 changes: 8 additions & 3 deletions exporters/jaeger/agent.go
Expand Up @@ -72,7 +72,7 @@ func newAgentClientUDP(params agentClientUDPParams) (*agentClientUDP, error) {
}

if params.MaxPacketSize <= 0 {
params.MaxPacketSize = udpPacketMaxLength - emitBatchOverhead
params.MaxPacketSize = udpPacketMaxLength
}

if params.AttemptReconnecting && params.AttemptReconnectInterval <= 0 {
Expand Down Expand Up @@ -126,6 +126,11 @@ func (a *agentClientUDP) EmitBatch(ctx context.Context, batch *gen.Batch) error
// drop the batch if serialization of process fails.
return err
}

maxPacketSize := a.maxPacketSize
if maxPacketSize > udpPacketMaxLength-emitBatchOverhead {
maxPacketSize = udpPacketMaxLength - emitBatchOverhead
}
totalSize := processSize
var spans []*gen.Span
for _, span := range batch.Spans {
Expand All @@ -134,12 +139,12 @@ func (a *agentClientUDP) EmitBatch(ctx context.Context, batch *gen.Batch) error
errs = append(errs, fmt.Errorf("thrift serialization failed: %v", span))
continue
}
if spanSize+processSize >= a.maxPacketSize {
if spanSize+processSize >= maxPacketSize {
// drop the span that exceeds the limit.
errs = append(errs, fmt.Errorf("span too large to send: %v", span))
continue
}
if totalSize+spanSize >= a.maxPacketSize {
if totalSize+spanSize >= maxPacketSize {
if err := a.flush(ctx, &gen.Batch{
Process: batch.Process,
Spans: spans,
Expand Down
4 changes: 2 additions & 2 deletions exporters/jaeger/agent_test.go
Expand Up @@ -73,7 +73,7 @@ func TestNewAgentClientUDPWithParamsDefaults(t *testing.T) {
})
assert.NoError(t, err)
assert.NotNil(t, agentClient)
assert.Equal(t, udpPacketMaxLength-emitBatchOverhead, agentClient.maxPacketSize)
assert.Equal(t, udpPacketMaxLength, agentClient.maxPacketSize)

if assert.IsType(t, &reconnectingUDPConn{}, agentClient.connUDP) {
assert.Equal(t, (*log.Logger)(nil), agentClient.connUDP.(*reconnectingUDPConn).logger)
Expand All @@ -97,7 +97,7 @@ func TestNewAgentClientUDPWithParamsReconnectingDisabled(t *testing.T) {
})
assert.NoError(t, err)
assert.NotNil(t, agentClient)
assert.Equal(t, udpPacketMaxLength-emitBatchOverhead, agentClient.maxPacketSize)
assert.Equal(t, udpPacketMaxLength, agentClient.maxPacketSize)

assert.IsType(t, &net.UDPConn{}, agentClient.connUDP)

Expand Down

0 comments on commit baa4427

Please sign in to comment.