-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[kafka] limit when
messaging.kafka.message.key
attribute is set to …
…basic types (#3379)
- Loading branch information
Showing
2 changed files
with
55 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
test/OpenTelemetry.AutoInstrumentation.Tests/KafkaInstrumentationTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
using System.Globalization; | ||
using FluentAssertions; | ||
using OpenTelemetry.AutoInstrumentation.Instrumentations.Kafka; | ||
using Xunit; | ||
|
||
namespace OpenTelemetry.AutoInstrumentation.Tests; | ||
|
||
public class KafkaInstrumentationTests | ||
{ | ||
[Theory] | ||
[InlineData("abc")] | ||
[InlineData(int.MaxValue)] | ||
[InlineData(uint.MaxValue)] | ||
[InlineData(long.MaxValue)] | ||
[InlineData(ulong.MaxValue)] | ||
[InlineData(float.MaxValue)] | ||
[InlineData(double.MaxValue)] | ||
public void MessageKeyValueIsExtractedForBasicType(object value) | ||
{ | ||
KafkaInstrumentation.ExtractMessageKeyValue(value).Should().Be(Convert.ToString(value, CultureInfo.InvariantCulture)); | ||
} | ||
|
||
[Fact] | ||
public void MessageKeyValueIsExtractedForDecimal() | ||
{ | ||
decimal input = decimal.MaxValue; | ||
KafkaInstrumentation.ExtractMessageKeyValue(input).Should().Be(Convert.ToString(input, CultureInfo.InvariantCulture)); | ||
} | ||
|
||
[Fact] | ||
public void MessageKeyValueIsNotExtractedForUnrecognizedType() | ||
{ | ||
var value = new byte[] { 1, 2, 3 }; | ||
KafkaInstrumentation.ExtractMessageKeyValue(value).Should().BeNull(); | ||
} | ||
} |