OpenTelemetry.PersistentStorage.FileSystem 1.0.2

Prefix Reserved
dotnet add package OpenTelemetry.PersistentStorage.FileSystem --version 1.0.2
                    
NuGet\Install-Package OpenTelemetry.PersistentStorage.FileSystem -Version 1.0.2
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="OpenTelemetry.PersistentStorage.FileSystem" Version="1.0.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="OpenTelemetry.PersistentStorage.FileSystem" Version="1.0.2" />
                    
Directory.Packages.props
<PackageReference Include="OpenTelemetry.PersistentStorage.FileSystem" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add OpenTelemetry.PersistentStorage.FileSystem --version 1.0.2
                    
#r "nuget: OpenTelemetry.PersistentStorage.FileSystem, 1.0.2"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package OpenTelemetry.PersistentStorage.FileSystem@1.0.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=OpenTelemetry.PersistentStorage.FileSystem&version=1.0.2
                    
Install as a Cake Addin
#tool nuget:?package=OpenTelemetry.PersistentStorage.FileSystem&version=1.0.2
                    
Install as a Cake Tool

Persistent Storage file based implementation

Status
Stability Stable
Code Owners @rajkumar-rangaraj

NuGet version badge NuGet download count badge codecov.io

This package provides an implementation of persistent-storage-abstractions based on local file system. This component can be used by OpenTelemetry exporters to improve the reliability of data delivery.

Installation

dotnet add package OpenTelemetry.PersistentStorage.FileSystem

Usage

Setup FileBlobProvider

using var persistentBlobProvider = new FileBlobProvider(@"C:/temp");
Configuration

Following is the complete list of parameters that FileBlobProvider constructor accepts to control its configuration:

path

Sets directory location where blobs are stored. Required.

maxSizeInBytes

Maximum allowed folder size. Optional. Default if not specified: 52428800 bytes.

New blobs are dropped after the folder size reaches maximum limit. A log message is written if blobs cannot be written. See Troubleshooting for more information.

maintenancePeriodInMilliseconds

Maintenance event runs at specified interval. Optional. Default if not specified: 120000ms.

During this event, the following tasks are performed:

  • Remove *.blob files for which the retention period has expired.
  • Remove *.tmp files for which the write timeout period has expired.
  • Update *.lock files to *.blob for which the lease period has expired.
  • Update available folder space.

For more details on file extensions(.blob, .tmp, .lock) see File naming section below.

retentionPeriodInMilliseconds

File retention period in milliseconds for the blob. Optional. Default if not specified: 172800000ms.

writeTimeoutInMilliseconds

Controls the timeout when writing a buffer to blob. Optional. Default if not specified: 60000ms.

Blob Operations

CreateBlob

TryCreateBlob(byte[] buffer, out PersistentBlob blob) or TryCreateBlob(byte[] buffer, int leasePeriodMilliseconds = 0, out PersistentBlob blob) can be used to create a blob (single file). The file stored will have .blob extension. If acquiring lease, the file will have .lock extension.

// Try create blob without acquiring lease
persistentBlobProvider.TryCreateBlob(data, out var blob);

// Try create blob and acquire lease
persistentBlobProvider.TryCreateBlob(data, 1000, out var blob);
GetBlob and GetBlobs

TryGetBlob can be used to read single blob or GetBlobs can be used to get list of all blobs stored on disk. The result will only include files with .blob extension.

// Get single blob from storage.
persistentBlobProvider.GetBlob(out var blob);

// List all blobs.
foreach (var blobItem in persistentBlobProvider.GetBlobs())
{
    Console.WriteLine(((FileBlob)blobItem).FullPath);
}
Lease

When reading data back from disk, TryLease(int leasePeriodMilliseconds) method should be used first to acquire lease on blob. This prevents it to be read concurrently, until the lease period expires. Leasing a blob changes the file extension to .lock.

blob.TryLease(1000);
Read

Once the lease is acquired on the blob, the data can be read using TryRead(out var data) method.

blob.TryRead(out var data);
Delete

TryDelete method can be used to delete the blob.

blob.TryDelete();

Example

using var persistentBlobProvider = new FileBlobProvider(@"C:/temp");

var data = Encoding.UTF8.GetBytes("Hello, World!");

// Create blob.
persistentBlobProvider.TryCreateBlob(data, out var createdBlob);

// List all blobs.
foreach (var blobItem in persistentBlobProvider.GetBlobs())
{
    Console.WriteLine(((FileBlob)blobItem).FullPath);
}

// Get single blob.
if (persistentBlobProvider.TryGetBlob(out var blob))
{
    // Lease before reading
    if (blob.TryLease(1000))
    {
        // Read
        if (blob.TryRead(out var outputData))
        {
            Console.WriteLine(Encoding.UTF8.GetString(outputData));
        }

        // Delete
        if (blob.TryDelete())
        {
            Console.WriteLine("Successfully deleted the blob");
        }
    }
}

File Details

File naming

Each call to CreateBlob methods create a single file(blob) at the configured directory path. Each file that is created has unique name in the format datetimestamp(ISO 8601)-GUID with current datetime. The file extension depends on the operation. When creating a blob, the file is stored with the .blob extension. If a lease is acquired on an existing file or on the file being created, the file extension is changed to .lock, along with the lease expiration time appended to its name in the format @datetimestamp(ISO 8601). The .tmp extension is used for files while data writing is in process.

Example file names:

  • 2024-05-15T174825.3027972Z-40386ee02b8a47f1b04afc281f33d712.blob
  • 2024-05-15T174825.3027972Z-40386ee02b8a47f1b04afc281f33d712.blob@2024-05-15T203551.2932278Z.lock
  • 2024-05-15T175941.2228167Z-6649ff8ce55144b88a99c440a0b9feea.blob.tmp

Data format and security

The data contained within the file(blob) is unencrypted and stored in its original, unprocessed format provided in the byte array. If there is a privacy concern, application owners SHOULD review and restrict the collection of private data. If specific security requirements need to be met, application owners SHOULD configure the directory to restrict access (ensuring that the process running your application has write access to this directory), thus preventing unauthorized users from reading its contents.

Data retention

A blob stored on disk persists until it is explicitly deleted using the TryDelete operation or is removed during the maintenance job upon the expiration of its retention period.

Troubleshooting

This component uses an EventSource with the name "OpenTelemetry-PersistentStorage-FileSystem" for its internal logging. Please follow the troubleshooting guide for OpenTelemetry .NET for instructions on how to capture the logs.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 is compatible.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on OpenTelemetry.PersistentStorage.FileSystem:

Package Downloads
Azure.Monitor.OpenTelemetry.Exporter

An OpenTelemetry .NET exporter that exports to Azure Monitor

Zongsoft.Diagnostics

This is a class library for OpenTelemetry protocols.

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on OpenTelemetry.PersistentStorage.FileSystem:

Repository Stars
Azure/azure-sdk-for-net
This repository is for active development of the Azure SDK for .NET. For consumers of the SDK we recommend visiting our public developer docs at https://learn.microsoft.com/dotnet/azure/ or our versioned developer docs at https://azure.github.io/azure-sdk-for-net.
Version Downloads Last Updated
1.0.2 11,009 11/13/2025
1.0.1 6,003,510 2/14/2025
1.0.0 20,462,898 8/29/2023
1.0.0-beta.2 1,140,607 4/17/2023