-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
206 additions
and
22 deletions.
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
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
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
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
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
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
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
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
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,45 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package log_test | ||
|
||
import ( | ||
"context" | ||
"strings" | ||
|
||
"go.opentelemetry.io/otel/log" | ||
logsdk "go.opentelemetry.io/otel/sdk/log" | ||
) | ||
|
||
// Use a processor which redacts sensitive data from some attributes. | ||
func ExampleProcessor_redact() { | ||
// Existing processor that emits telemetry. | ||
var processor logsdk.Processor = logsdk.NewBatchProcessor(nil) | ||
|
||
// Wrap the processor so that it redacts values from token attributes. | ||
processor = &RedactTokensProcessor{processor} | ||
|
||
// The created processor can then be registered with | ||
// the OpenTelemetry Logs SDK using the WithProcessor option. | ||
_ = logsdk.NewLoggerProvider( | ||
logsdk.WithProcessor(processor), | ||
) | ||
} | ||
|
||
// RedactTokensProcessor is a [logsdk.Processor] decorator that redacts values | ||
// from attributes containing "token" in the key. | ||
type RedactTokensProcessor struct { | ||
logsdk.Processor | ||
} | ||
|
||
// OnEmit redacts values from attributes containing "token" in the key | ||
// by replacing them with a REDACTED value. | ||
func (s *RedactTokensProcessor) OnEmit(ctx context.Context, record logsdk.Record) error { | ||
record.WalkAttributes(func(kv log.KeyValue) bool { | ||
if strings.Contains(strings.ToLower(kv.Key), "token") { | ||
record.AddAttributes(log.String(kv.Key, "REDACTED")) | ||
} | ||
return true | ||
}) | ||
return s.Processor.OnEmit(ctx, record) | ||
} |
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
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
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