Skip to content
This repository has been archived by the owner on Apr 28, 2022. It is now read-only.

Commit

Permalink
Limit UDPs max span bytes when using Thrift (#210)
Browse files Browse the repository at this point in the history
* Fix typos
* Limit maxPacketSize for UdpSender

Signed-off-by: Kraemer, Benjamin <[email protected]>
  • Loading branch information
Falco20019 authored Apr 19, 2021
1 parent 4d29d27 commit 40b078c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ public enum ProtocolType

protected int MaxSpanBytes { get; }

/// <param name="protocolType">Protocol type (compact or binary)</param<
/// <param name="maxPacketSize">If 0 it will use default value <see cref="ThriftUdpTransport.MAX_PACKET_SIZE"/>.</param>
/// <param name="protocolType">Protocol type (compact or binary)</param>
/// <param name="maxPacketSize">If 0 it will use default value <see cref="ThriftUdpClientTransport.MaxPacketSize"/>.</param>
public ThriftSenderBase(ProtocolType protocolType, int maxPacketSize)
{
switch (protocolType)
Expand Down
9 changes: 7 additions & 2 deletions src/Senders/Jaeger.Senders.Thrift/UdpSender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,10 @@ public UdpSender()

/// <param name="host">If empty it will use <see cref="DefaultAgentUdpHost"/>.</param>
/// <param name="port">If 0 it will use <see cref="DefaultAgentUdpCompactPort"/>.</param>
/// <param name="maxPacketSize">If 0 it will use <see cref="ThriftUdpClientTransport.MaxPacketSize"/>.</param>
/// <param name="maxPacketSize">If 0 it will use <see cref="ThriftUdpClientTransport.MaxPacketSize"/>. Must not exceed <see cref="ThriftUdpClientTransport.MaxPacketSize"/>.</param>
public UdpSender(string host, int port, int maxPacketSize)
: base(ProtocolType.Compact, maxPacketSize)
{

if (string.IsNullOrEmpty(host))
{
host = DefaultAgentUdpHost;
Expand All @@ -51,6 +50,12 @@ public UdpSender(string host, int port, int maxPacketSize)
port = DefaultAgentUdpCompactPort;
}

if (maxPacketSize > ThriftUdpClientTransport.MaxPacketSize)
{
throw new NotSupportedException($"Using a packet size bigger than {ThriftUdpClientTransport.MaxPacketSize} "
+ "can lead to lost traces and is therefore not supported.");
}

_udpTransport = new ThriftUdpClientTransport(host, port);
_agentClient = new Agent.Client(ProtocolFactory.GetProtocol(_udpTransport));
}
Expand Down
23 changes: 23 additions & 0 deletions test/Senders/Jaeger.Senders.Thrift.Tests/UdpSenderTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Net.Sockets;
using System.Reflection;
using Jaeger.Reporters;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using OpenTracing.Noop;
using OpenTracing.Util;
using Xunit;

namespace Jaeger.Senders.Thrift.Tests
{
public class UdpSenderTests
{
[Fact]
public void TestSenderWithAgentDataFromEnv()
{
Assert.Throws<NotSupportedException>(() => new UdpSender("jaeger-agent", 6832, 65535));
}
}
}

0 comments on commit 40b078c

Please sign in to comment.