Skip to content

Commit 65e0744

Browse files
committed
Fix formatting issues in OtlpExporterOptionsExtensions.cs
- Ensure consistent indentation to comply with StyleCop rule SA1137. - Remove multiple consecutive blank lines to comply with StyleCop rule SA1507.
1 parent cda3c88 commit 65e0744

File tree

1 file changed

+36
-35
lines changed

1 file changed

+36
-35
lines changed

src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptionsExtensions.cs

+36-35
Original file line numberDiff line numberDiff line change
@@ -49,51 +49,52 @@ public static Channel CreateChannel(this OtlpExporterOptions options)
4949
public static Metadata GetMetadataFromHeaders(this OtlpExporterOptions options) => options.GetHeaders<Metadata>((m, k, v) => m.Add(k, v));
5050
#endif
5151

52-
public static THeaders GetHeaders<THeaders>(this OtlpExporterOptions options, Action<THeaders, string, string> addHeader)
53-
where THeaders : new()
54-
{
55-
var optionHeaders = options.Headers;
56-
var headers = new THeaders();
57-
if (!string.IsNullOrEmpty(optionHeaders))
52+
public static THeaders GetHeaders<THeaders>(this OtlpExporterOptions options, Action<THeaders, string, string> addHeader)
53+
where THeaders : new()
5854
{
59-
optionHeaders = Uri.UnescapeDataString(optionHeaders);
60-
ReadOnlySpan<char> headersSpan = optionHeaders.AsSpan();
61-
62-
while (!headersSpan.IsEmpty)
55+
var optionHeaders = options.Headers;
56+
var headers = new THeaders();
57+
if (!string.IsNullOrEmpty(optionHeaders))
6358
{
64-
int commaIndex = headersSpan.IndexOf(',');
65-
ReadOnlySpan<char> pair;
66-
if (commaIndex == -1)
67-
{
68-
pair = headersSpan;
69-
headersSpan = ReadOnlySpan<char>.Empty;
70-
}
71-
else
72-
{
73-
pair = headersSpan.Slice(0, commaIndex);
74-
headersSpan = headersSpan.Slice(commaIndex + 1);
75-
}
59+
// According to the specification, URL-encoded headers must be supported.
60+
optionHeaders = Uri.UnescapeDataString(optionHeaders);
61+
ReadOnlySpan<char> headersSpan = optionHeaders.AsSpan();
7662

77-
int equalIndex = pair.IndexOf('=');
78-
if (equalIndex == -1)
63+
while (!headersSpan.IsEmpty)
7964
{
80-
throw new ArgumentException("Headers provided in an invalid format.");
65+
int commaIndex = headersSpan.IndexOf(',');
66+
ReadOnlySpan<char> pair;
67+
if (commaIndex == -1)
68+
{
69+
pair = headersSpan;
70+
headersSpan = ReadOnlySpan<char>.Empty;
71+
}
72+
else
73+
{
74+
pair = headersSpan.Slice(0, commaIndex);
75+
headersSpan = headersSpan.Slice(commaIndex + 1);
76+
}
77+
78+
int equalIndex = pair.IndexOf('=');
79+
if (equalIndex == -1)
80+
{
81+
throw new ArgumentException("Headers provided in an invalid format.");
82+
}
83+
84+
var key = pair.Slice(0, equalIndex).ToString().Trim();
85+
var value = pair.Slice(equalIndex + 1).ToString().Trim();
86+
addHeader(headers, key, value);
8187
}
88+
}
8289

83-
var key = pair.Slice(0, equalIndex).ToString().Trim();
84-
var value = pair.Slice(equalIndex + 1).ToString().Trim();
85-
addHeader(headers, key, value);
90+
foreach (var header in OtlpExporterOptions.StandardHeaders)
91+
{
92+
addHeader(headers, header.Key, header.Value);
8693
}
87-
}
8894

89-
foreach (var header in OtlpExporterOptions.StandardHeaders)
90-
{
91-
addHeader(headers, header.Key, header.Value);
95+
return headers;
9296
}
9397

94-
return headers;
95-
}
96-
9798

9899
public static OtlpExporterTransmissionHandler GetExportTransmissionHandler(this OtlpExporterOptions options, ExperimentalOptions experimentalOptions, OtlpSignalType otlpSignalType)
99100
{

0 commit comments

Comments
 (0)