open-telemetry / opentelemetry-collector-contrib

Contrib repository for the OpenTelemetry Collector
https://opentelemetry.io
Apache License 2.0
2.9k stars 2.27k forks source link

[pkg/ottl] Add support PCRE2 regex syntax #32167

Open aofodo opened 5 months ago

aofodo commented 5 months ago

Component(s)

processor/transform

Is your feature request related to a problem? Please describe.

I need to mask PANs (card numbers) in logs. Card numbers can be in different versions. With different dividers, different lengths. It is important that other data is not accidentally masked. To do this, I use a complex regular expression, including lookahead and other features of the PCRE2 syntax. Without the syntax capabilities of PCRE2, it is impossible to fully mask card numbers

Describe the solution you'd like

Add support PCRE2 syntax in processor/transform for replace_pattern and replace_all_patterns

Describe alternatives you've considered

No response

Additional context

No response

github-actions[bot] commented 5 months ago

Pinging code owners:

See Adding Labels via Comments if you do not have permissions to add labels yourself.

TylerHelmuth commented 5 months ago

@aofodo we use Go's built-in package for regex which I don't believe supports PCRE2 regexes by design. We'd need to find a suitable library to implement this feature request.

amal-v commented 5 months ago

We are trying to remove the . from the k8sattributes for k8s labels. For Eg k8s.pods.labels.service.version=1 to k8s.pods.labels.service_version=1. We require some advanced regex like PCRE2 to perform these operations.

TylerHelmuth commented 5 months ago

@amal-v can you share the PCRE2 regex you'd like to use for your use case?

rdeavila94 commented 5 months ago

Ditto this. I have a use case where a span attribute is a JSON string and I need to obfuscate the JSON values with the exception of some that correspond to a specific JSON key. Doesn't seem possible without a negative lookbehind.

for reference

transform:
  error_mode: ignore
  trace_statements:
    - context: span
      statements:
        - "replace_pattern(attributes[\"my-attribute\"], \"(?<!\\\"(key1|key2)\\\": )\\\"[^\\\"]+\\\"\", \"?\")"

There's probably a way to do this by transforming across multiple transformation stages but a single regex solution is much preferable.

github-actions[bot] commented 5 months ago

Pinging code owners for pkg/ottl: @TylerHelmuth @kentquirk @bogdandrutu @evan-bradley. See Adding Labels via Comments if you do not have permissions to add labels yourself.

TylerHelmuth commented 5 months ago

Negative lookahead isn't supported by Go's regexp package, so we'd need another regular expression package that does.

aofodo commented 5 months ago

I haven't had a chance to work with it, but this package go.arsenm.dev/pcre looks good. But it has limitations in target os and arch

TylerHelmuth commented 5 months ago

But it has limitations in target os and arch

That will be a dealbreaker as OTTL needs to work in all the target architectures supported by https://github.com/open-telemetry/opentelemetry-collector-releases

github-actions[bot] commented 2 months ago

This issue has been inactive for 60 days. It will be closed in 60 days if there is no activity. To ping code owners by adding a component label, see Adding Labels via Comments, or if you are unsure of which component this issue relates to, please ping @open-telemetry/collector-contrib-triagers. If this issue is still relevant, please ping the code owners or leave a comment explaining why it is still relevant. Otherwise, please close it.

Pinging code owners:

See Adding Labels via Comments if you do not have permissions to add labels yourself.

github-actions[bot] commented 3 weeks ago

This issue has been inactive for 60 days. It will be closed in 60 days if there is no activity. To ping code owners by adding a component label, see Adding Labels via Comments, or if you are unsure of which component this issue relates to, please ping @open-telemetry/collector-contrib-triagers. If this issue is still relevant, please ping the code owners or leave a comment explaining why it is still relevant. Otherwise, please close it.

Pinging code owners:

See Adding Labels via Comments if you do not have permissions to add labels yourself.