Skip to content

Commit 78dffdc

Browse files
[Exporter.OTLP] Require path when disk-retry is configured (#7106)
Co-authored-by: Rajkumar Rangaraj <rajrang@microsoft.com>
1 parent 6fc51c6 commit 78dffdc

File tree

4 files changed

+60
-11
lines changed

4 files changed

+60
-11
lines changed

src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,20 @@ Notes](../../RELEASENOTES.md).
77

88
## Unreleased
99

10+
* **Breaking change:** Fixed an insecure disk retry default. Disk retry now
11+
requires `OTEL_DOTNET_EXPERIMENTAL_OTLP_DISK_RETRY_DIRECTORY_PATH` when
12+
`OTEL_DOTNET_EXPERIMENTAL_OTLP_RETRY=disk` is configured. The exporter no
13+
longer falls back to a shared temp directory by default.
14+
To retain the previous behaviour, set the
15+
`OTEL_DOTNET_EXPERIMENTAL_OTLP_DISK_RETRY_DIRECTORY_PATH` environment
16+
variable to the value one of the following environment variables:
17+
18+
* `TMP`, `TMP`, or `USERPROFILE` ([Windows](https://learn.microsoft.com/windows/win32/api/fileapi/nf-fileapi-gettemppath2w#remarks))
19+
* `TMPDIR` (or the literal value `/tmp/`) ([Linux](https://learn.microsoft.com/dotnet/api/system.io.path.gettemppath?tabs=linux),
20+
[macOS](https://learn.microsoft.com/dotnet/api/system.io.path.gettemppath?tabs=macos)).
21+
22+
([#7106](https://github.com/open-telemetry/opentelemetry-dotnet/pull/7106))
23+
1024
* Fixed an issue in OTLP/gRPC retry handling where parsing gRPC status.
1125
([#7064](https://github.com/open-telemetry/opentelemetry-dotnet/pull/7064))
1226

src/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/ExperimentalOptions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ public ExperimentalOptions(IConfiguration configuration)
4242
}
4343
else
4444
{
45-
// Fallback to temp location.
46-
this.DiskRetryDirectoryPath = Path.GetTempPath();
45+
throw new NotSupportedException(
46+
$"Retry Policy '{retryPolicy}' requires '{OtlpDiskRetryDirectoryPathEnvVar}' to be configured.");
4747
}
4848
}
4949
else

src/OpenTelemetry.Exporter.OpenTelemetryProtocol/README.md

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -652,12 +652,9 @@ want to solicit feedback from the community.
652652
Added in `1.8.0`.
653653

654654
* When set to `disk`, it enables retries by storing telemetry on disk during
655-
transient errors. The default path where the telemetry is stored is
656-
obtained by calling
657-
[Path.GetTempPath()](https://learn.microsoft.com/dotnet/api/system.io.path.gettemppath)
658-
or can be customized by setting
659-
`OTEL_DOTNET_EXPERIMENTAL_OTLP_DISK_RETRY_DIRECTORY_PATH` environment
660-
variable.
655+
transient errors. You MUST set
656+
`OTEL_DOTNET_EXPERIMENTAL_OTLP_DISK_RETRY_DIRECTORY_PATH` to a dedicated
657+
directory location.
661658

662659
The OTLP exporter utilizes a forked version of the
663660
[OpenTelemetry.PersistentStorage.FileSystem](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/tree/main/src/OpenTelemetry.PersistentStorage.FileSystem)

test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsExtensionsTests.cs

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,14 +102,11 @@ public void AppendPathIfNotPresent_TracesPath_AppendsCorrectly(string input, str
102102
#pragma warning disable CS0618 // Suppressing gRPC obsolete warning
103103
[InlineData(OtlpExportProtocol.Grpc, typeof(OtlpGrpcExportClient), false, 10000, null)]
104104
[InlineData(OtlpExportProtocol.Grpc, typeof(OtlpGrpcExportClient), false, 10000, "in_memory")]
105-
[InlineData(OtlpExportProtocol.Grpc, typeof(OtlpGrpcExportClient), false, 10000, "disk")]
106105
#pragma warning restore CS0618 // Suppressing gRPC obsolete warning
107106
[InlineData(OtlpExportProtocol.HttpProtobuf, typeof(OtlpHttpExportClient), false, 10000, null)]
108107
[InlineData(OtlpExportProtocol.HttpProtobuf, typeof(OtlpHttpExportClient), true, 8000, null)]
109108
[InlineData(OtlpExportProtocol.HttpProtobuf, typeof(OtlpHttpExportClient), false, 10000, "in_memory")]
110109
[InlineData(OtlpExportProtocol.HttpProtobuf, typeof(OtlpHttpExportClient), true, 8000, "in_memory")]
111-
[InlineData(OtlpExportProtocol.HttpProtobuf, typeof(OtlpHttpExportClient), false, 10000, "disk")]
112-
[InlineData(OtlpExportProtocol.HttpProtobuf, typeof(OtlpHttpExportClient), true, 8000, "disk")]
113110
public void GetTransmissionHandler_InitializesCorrectHandlerExportClientAndTimeoutValue(OtlpExportProtocol protocol, Type exportClientType, bool customHttpClient, int expectedTimeoutMilliseconds, string? retryStrategy)
114111
{
115112
var exporterOptions = new OtlpExporterOptions() { Protocol = protocol };
@@ -129,6 +126,47 @@ public void GetTransmissionHandler_InitializesCorrectHandlerExportClientAndTimeo
129126
AssertTransmissionHandler(transmissionHandler, exportClientType, expectedTimeoutMilliseconds, retryStrategy);
130127
}
131128

129+
[Theory]
130+
#pragma warning disable CS0618 // Suppressing gRPC obsolete warning
131+
[InlineData(OtlpExportProtocol.Grpc, typeof(OtlpGrpcExportClient), false, 10000)]
132+
#pragma warning restore CS0618 // Suppressing gRPC obsolete warning
133+
[InlineData(OtlpExportProtocol.HttpProtobuf, typeof(OtlpHttpExportClient), false, 10000)]
134+
[InlineData(OtlpExportProtocol.HttpProtobuf, typeof(OtlpHttpExportClient), true, 8000)]
135+
public void GetTransmissionHandler_DiskRetryWithDirectory_InitializesCorrectHandlerExportClientAndTimeoutValue(OtlpExportProtocol protocol, Type exportClientType, bool customHttpClient, int expectedTimeoutMilliseconds)
136+
{
137+
var exporterOptions = new OtlpExporterOptions() { Protocol = protocol };
138+
if (customHttpClient)
139+
{
140+
exporterOptions.HttpClientFactory = () =>
141+
{
142+
return new HttpClient { Timeout = TimeSpan.FromMilliseconds(expectedTimeoutMilliseconds) };
143+
};
144+
}
145+
146+
var configuration = new ConfigurationBuilder()
147+
.AddInMemoryCollection(
148+
new Dictionary<string, string?>
149+
{
150+
[ExperimentalOptions.OtlpRetryEnvVar] = "disk",
151+
[ExperimentalOptions.OtlpDiskRetryDirectoryPathEnvVar] = Path.GetTempPath(),
152+
})
153+
.Build();
154+
155+
var transmissionHandler = exporterOptions.GetExportTransmissionHandler(new ExperimentalOptions(configuration), OtlpSignalType.Traces);
156+
AssertTransmissionHandler(transmissionHandler, exportClientType, expectedTimeoutMilliseconds, "disk");
157+
}
158+
159+
[Fact]
160+
public void GetTransmissionHandler_DiskRetryWithoutDirectory_Throws()
161+
{
162+
var configuration = new ConfigurationBuilder()
163+
.AddInMemoryCollection(new Dictionary<string, string?> { [ExperimentalOptions.OtlpRetryEnvVar] = "disk" })
164+
.Build();
165+
166+
var exception = Assert.Throws<NotSupportedException>(() => new ExperimentalOptions(configuration));
167+
Assert.Contains(ExperimentalOptions.OtlpDiskRetryDirectoryPathEnvVar, exception.Message, StringComparison.Ordinal);
168+
}
169+
132170
[Theory]
133171
[InlineData("Traces", "traces")]
134172
[InlineData("Logs", "logs")]

0 commit comments

Comments
 (0)