Skip to content

Commit

Permalink
Set span context destination service name and type to empty string (#…
Browse files Browse the repository at this point in the history
…1564)

This commit updates the Span context destination service name
and type to set them to empty string by default.

Both fields are marked as obsolete and will be removed in a
future version, but need to be sent as empty strings for
older APM server compatibility, which validates the presence
of these fields.

Fixes #1563
  • Loading branch information
russcam authored Nov 15, 2021
1 parent 9a6d3b0 commit c1624c4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/Elastic.Apm/Api/Destination.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ public class DestinationService
/// Identifier for the destination service (e.g. 'http://elastic.co', 'elasticsearch', 'rabbitmq')"
/// </summary>
[MaxLength]
[Obsolete("This field will be removed in future versions")]
public string Name { get; set; }
[Obsolete("This field is unused by Elastic APM and will be removed in a future version")]
public string Name { get; set; } = string.Empty;

/// <summary>
/// Identifier for the destination service resource being operated on (e.g. 'http://elastic.co:80', 'elasticsearch',
Expand All @@ -87,8 +87,8 @@ public class DestinationService
/// Type of the destination service (e.g. 'db', 'elasticsearch'). Should typically be the same as span.type.
/// </summary>
[MaxLength]
[Obsolete("This field will be removed in future versions")]
public string Type { get; set; }
[Obsolete("This field is unused by Elastic APM and will be removed in a future version")]
public string Type { get; set; } = string.Empty;
}

/// <summary>
Expand Down
9 changes: 9 additions & 0 deletions test/Elastic.Apm.Tests/SerializationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,15 @@ public void System_Should_Serialize_ConfiguredHostName_And_DetectedHostName()
detectedHostName.Should().NotBeNull();
}

[Fact]
public void SpanContext_Destination_Service_Should_Serialize_Name_And_Type_As_Empty_String_By_Default()
{
var destinationService = new Destination.DestinationService();

var json = _payloadItemSerializer.Serialize(destinationService);
json.Should().Contain("\"name\":\"\"").And.Contain("\"type\":\"\"");
}

/// <summary>
/// A dummy type for tests.
/// </summary>
Expand Down

0 comments on commit c1624c4

Please sign in to comment.