mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2025-03-03 14:52:56 +02:00
emitBatchOverhead should only be used for splitting spans into batches (#2512)
* emitBatchOverhead should only be used for splitting spans into batches (#2503) * limit max packet size parameter
This commit is contained in:
parent
0b03aae0da
commit
0c1f156b5b
@ -15,7 +15,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
|
|||||||
|
|
||||||
### Changed
|
### 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
|
### Deprecated
|
||||||
|
|
||||||
|
@ -71,8 +71,8 @@ func newAgentClientUDP(params agentClientUDPParams) (*agentClientUDP, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if params.MaxPacketSize <= 0 {
|
if params.MaxPacketSize <= 0 || params.MaxPacketSize > udpPacketMaxLength {
|
||||||
params.MaxPacketSize = udpPacketMaxLength - emitBatchOverhead
|
params.MaxPacketSize = udpPacketMaxLength
|
||||||
}
|
}
|
||||||
|
|
||||||
if params.AttemptReconnecting && params.AttemptReconnectInterval <= 0 {
|
if params.AttemptReconnecting && params.AttemptReconnectInterval <= 0 {
|
||||||
@ -126,6 +126,11 @@ func (a *agentClientUDP) EmitBatch(ctx context.Context, batch *gen.Batch) error
|
|||||||
// drop the batch if serialization of process fails.
|
// drop the batch if serialization of process fails.
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
maxPacketSize := a.maxPacketSize
|
||||||
|
if maxPacketSize > udpPacketMaxLength-emitBatchOverhead {
|
||||||
|
maxPacketSize = udpPacketMaxLength - emitBatchOverhead
|
||||||
|
}
|
||||||
totalSize := processSize
|
totalSize := processSize
|
||||||
var spans []*gen.Span
|
var spans []*gen.Span
|
||||||
for _, span := range batch.Spans {
|
for _, span := range batch.Spans {
|
||||||
@ -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))
|
errs = append(errs, fmt.Errorf("thrift serialization failed: %v", span))
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if spanSize+processSize >= a.maxPacketSize {
|
if spanSize+processSize >= maxPacketSize {
|
||||||
// drop the span that exceeds the limit.
|
// drop the span that exceeds the limit.
|
||||||
errs = append(errs, fmt.Errorf("span too large to send: %v", span))
|
errs = append(errs, fmt.Errorf("span too large to send: %v", span))
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if totalSize+spanSize >= a.maxPacketSize {
|
if totalSize+spanSize >= maxPacketSize {
|
||||||
if err := a.flush(ctx, &gen.Batch{
|
if err := a.flush(ctx, &gen.Batch{
|
||||||
Process: batch.Process,
|
Process: batch.Process,
|
||||||
Spans: spans,
|
Spans: spans,
|
||||||
|
@ -73,7 +73,7 @@ func TestNewAgentClientUDPWithParamsDefaults(t *testing.T) {
|
|||||||
})
|
})
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.NotNil(t, agentClient)
|
assert.NotNil(t, agentClient)
|
||||||
assert.Equal(t, udpPacketMaxLength-emitBatchOverhead, agentClient.maxPacketSize)
|
assert.Equal(t, udpPacketMaxLength, agentClient.maxPacketSize)
|
||||||
|
|
||||||
if assert.IsType(t, &reconnectingUDPConn{}, agentClient.connUDP) {
|
if assert.IsType(t, &reconnectingUDPConn{}, agentClient.connUDP) {
|
||||||
assert.Equal(t, (*log.Logger)(nil), agentClient.connUDP.(*reconnectingUDPConn).logger)
|
assert.Equal(t, (*log.Logger)(nil), agentClient.connUDP.(*reconnectingUDPConn).logger)
|
||||||
@ -97,7 +97,7 @@ func TestNewAgentClientUDPWithParamsReconnectingDisabled(t *testing.T) {
|
|||||||
})
|
})
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.NotNil(t, agentClient)
|
assert.NotNil(t, agentClient)
|
||||||
assert.Equal(t, udpPacketMaxLength-emitBatchOverhead, agentClient.maxPacketSize)
|
assert.Equal(t, udpPacketMaxLength, agentClient.maxPacketSize)
|
||||||
|
|
||||||
assert.IsType(t, &net.UDPConn{}, agentClient.connUDP)
|
assert.IsType(t, &net.UDPConn{}, agentClient.connUDP)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user