EZ.Redact.Lgpd.OpenTelemetry 2.1.0

dotnet add package EZ.Redact.Lgpd.OpenTelemetry --version 2.1.0
                    
NuGet\Install-Package EZ.Redact.Lgpd.OpenTelemetry -Version 2.1.0
                    
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="EZ.Redact.Lgpd.OpenTelemetry" Version="2.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="EZ.Redact.Lgpd.OpenTelemetry" Version="2.1.0" />
                    
Directory.Packages.props
<PackageReference Include="EZ.Redact.Lgpd.OpenTelemetry" />
                    
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 EZ.Redact.Lgpd.OpenTelemetry --version 2.1.0
                    
#r "nuget: EZ.Redact.Lgpd.OpenTelemetry, 2.1.0"
                    
#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 EZ.Redact.Lgpd.OpenTelemetry@2.1.0
                    
#: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=EZ.Redact.Lgpd.OpenTelemetry&version=2.1.0
                    
Install as a Cake Addin
#tool nuget:?package=EZ.Redact.Lgpd.OpenTelemetry&version=2.1.0
                    
Install as a Cake Tool

EZ.Redact.Lgpd.OpenTelemetry

NuGet Version License: MIT .NET 8.0+

EZ.Redact.Lgpd.OpenTelemetry é uma extensão do ecossistema EZ.Redact.Lgpd que aplica redação de dados sensíveis (LGPD) em traces do OpenTelemetry. Ela redige tags e baggage de spans automaticamente antes da exportação, além de fornecer uma API fluente para criar eventos com dados mascarados.


Instalação

dotnet add package EZ.Redact.Lgpd.OpenTelemetry

Registre os serviços no DI com AddLGPDRedaction() e configure a redação OpenTelemetry:

using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;

var builder = WebApplication.CreateBuilder(args);
builder.Services.AddLGPDRedaction();
builder.Logging.EnableRedaction(options => options.ApplyDiscriminator = false);

Exemplo rápido

using EZ.Redact.Lgpd.OpenTelemetry;
using EZ.Redact.Lgpd.OpenTelemetry.Processors;
using OpenTelemetry.Trace;

builder.Services.AddLGPDRedaction()
    .AddOpenTelemetryRedaction(options =>
    {
        options.RedactTags("user.cpf", "user.email", "customer.document");
        options.RedactBaggage("user.cpf", "user.email");
    });

builder.Services.AddOpenTelemetry()
    .WithTracing(tracing => tracing
        .AddAspNetCoreInstrumentation()
        .AddProcessor(sp => sp.GetRequiredService<LgpdRedactionProcessor>()));

Tags e baggage cujos nomes estiverem na blacklist são redigidos automaticamente ao final do span:

Entrada Resultado
123.456.789-00 123*******00
joao.silva@example.com joa***********com

Eventos redigidos

Crie eventos com dados sensíveis usando a API fluente:

activity.CreateRedactedEvent(
    "Cliente {cpf} realizou saque de {valor} na conta {conta}",
    redactService)
    .WithRedacted("cpf", DadoPessoal.CPF, "123.456.789-00")
    .WithRaw("valor", "R$ 1.500,00")
    .WithRedacted("conta", DadoPessoal.ContaBancaria, "12345-6")
    .Add();

Saída do evento redigido:

Cliente ***.***.***-** realizou saque de R$ 1.500,00 na conta *****-*

API do builder

Método Descrição
WithRedacted(key, tipo, value) Redige o valor usando ILGPDRedactService antes de armazenar
WithRaw(key, value) Armazena o valor sem alteração
Add() Substitui os placeholders {key} no template e chama activity.AddEvent()

Configuração

LgpdOpenTelemetryOptions

Método Descrição
RedactTags(params string[] tags) Adiciona nomes de tags que devem ser redigidas ao final do span
RedactBaggage(params string[] keys) Adiciona nomes de baggage que devem ser redigidas ao final do span
builder.Services.AddLGPDRedaction()
    .AddOpenTelemetryRedaction(options =>
    {
        options.RedactTags("user.cpf", "user.email", "user.nome", "customer.document");
        options.RedactBaggage("user.cpf", "user.email");
    });

Comportamento

LgpdRedactionProcessor

O LgpdRedactionProcessor implementa BaseProcessor<Activity> do OpenTelemetry e:

  1. No método OnEnd intercepta cada span antes da exportação
  2. Verifica se a redação está habilitada — respeita o controle configurado no Core (via ILGPDRedactService)
  3. Para cada tag cujo nome estiver na blacklist, substitui o valor pela redação genérica
  4. Para cada baggage cujo nome estiver na blacklist, substitui o valor pela redação genérica

Redação genérica

Preserva 3 caracteres no início e 3 no final do valor, substituindo o meio por asteriscos:

"123.456.789-00" → "123*******00"
"joao@example.com" → "joa*******com"
"curto" → "curto" (inalterado — < 6 caracteres)

Projetos Relacionados

Projeto Descrição
EZ.Redact.Lgpd.Core Biblioteca central de redação de dados sensíveis LGPD
EZ.Redact.Lgpd.EntityFramework Redação em consultas Entity Framework
EZ.Redact.Lgpd.Json Redação em serialização JSON
EZ.Redact.Lgpd.MongoDb Redação em consultas MongoDB
EZ.Redact.Lgpd.Xml Redação em serialização XML

Licença

Distribuído sob a licença MIT.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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 is compatible.  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 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.1.0 134 5/29/2026