Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[resource host+process] Allow host name and process owner attributes to be excluded #2084

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

flaviocdc
Copy link
Contributor

Changes

Process owner and Host name may contain private data, so there has to be a way to not include them as part of the telemetry record.

In order to achieve this, I'm adding an extra parameter to AddHostDetector and AddProcessDetector that allows consumers on the detectors to control whether or not this data will be added to the Resource.

Merge requirement checklist

  • CONTRIBUTING guidelines followed (license requirements, nullable enabled, static analysis, etc.)
  • Unit tests added/updated
  • Appropriate CHANGELOG.md files updated for non-trivial changes
  • Changes in public API reviewed (if applicable)

@github-actions github-actions bot added comp:resources.host Things related to OpenTelemetry.Resources.Host comp:resources.process Things related to OpenTelemetry.Resources.Process labels Sep 19, 2024
Copy link

codecov bot commented Sep 19, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 77.03%. Comparing base (71655ce) to head (99cbf77).
Report is 439 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2084      +/-   ##
==========================================
+ Coverage   73.91%   77.03%   +3.12%     
==========================================
  Files         267        5     -262     
  Lines        9615      135    -9480     
==========================================
- Hits         7107      104    -7003     
+ Misses       2508       31    -2477     
Flag Coverage Δ
unittests-Resources.Host 74.79% <100.00%> (?)
unittests-Resources.Process 100.00% <100.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/OpenTelemetry.Resources.Host/HostDetector.cs 78.57% <100.00%> (ø)
...ry.Resources.Host/HostResourceBuilderExtensions.cs 100.00% <100.00%> (ø)
...OpenTelemetry.Resources.Process/ProcessDetector.cs 100.00% <100.00%> (ø)
...ources.Process/ProcessResourceBuilderExtensions.cs 100.00% <100.00%> (ø)

... and 268 files with indirect coverage changes

@flaviocdc flaviocdc marked this pull request as ready for review September 19, 2024 20:01
@flaviocdc flaviocdc requested a review from a team as a code owner September 19, 2024 20:01
Copy link
Member

@CodeBlanch CodeBlanch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@CodeBlanch
Copy link
Member

@CodeBlanch CodeBlanch changed the title Allow host name and process owner to be excluded from the Resource [resource host+process] Allow host name and process owner attributes to be excluded Sep 19, 2024
@Kielek
Copy link
Contributor

Kielek commented Sep 20, 2024

Note for myself from https://opentelemetry.io/docs/specs/semconv/general/attribute-requirement-level/#recommended:

Instrumentations SHOULD add the attribute by default if it’s readily available and can be efficiently populated. Instrumentations MAY offer a configuration option to disable Recommended attributes.

Instrumentations that decide not to populate Recommended attributes due to performance, security, privacy, or other consideration by default, SHOULD allow for users to opt-in to emit them as defined for the Opt-In requirement level (if the attributes are logically applicable)

@Kielek
Copy link
Contributor

Kielek commented Sep 20, 2024

There is couple types of the resources

  • Required - always should be available
  • Conditionally required - always should be available
  • Recommended - it MAY be possibility to opt-out
  • Opt-in - it may be possibility to opt-in

Host resource detector sem conv contains 7 recommended and 2 Opt-in attributes. Not all of them are implemented here.

I think that we need better to expose this publicly (not on the merge level, it can be on adding method). Adding ~9 boolean attributes is not good idea IMO.

Maybe we should have
Somethin like:
public static ResourceBuilder AddProcessDetector(this ResourceBuilder builder, IEnumerable<string> optOutAttributes, Enumerable<string> optInAttributes)
or
public static ResourceBuilder AddProcessDetector(this ResourceBuilder builder, IEnumerable<HostOptOutAttribute> optOutAttributes, Enumerable<HostOptInAttribute> optInAttributes)?

If operate on strings - what should happen when someone want to disable Required attribute or is passing attribute not supported by the given resource detectot?

It will be great to give it also possibility to configure it from env vars to make it AutoInstrumentation friendly.

@CodeBlanch
Copy link
Member

@Kielek Personally I'm not a fan of APIs which rely on magic strings. Could we do something more strongly typed?

public static class HostResourceBuilderExtensions
{
    public static ResourceBuilder AddHostDetector(this ResourceBuilder builder) {}
    public static ResourceBuilder AddHostDetector(this ResourceBuilder builder, Action<HostResourceOptions> configure) {}
}

public sealed class HostResourceOptions
{
    internal HostResourceOptions(IConfiguration configuration)
    {
        var config = configuration.GetValue("OTEL_DOTNET_HOST_RESOURCE_ATTRIBUTES", (string?)null);
        if (config != null)
        {
            // TODO: Parse config and apply onto bools (somehow)
        }
    }

    #region Recommended (on by default)
    public bool IncludeArchitecture { get; set; } = true;

    public bool IncludeId { get; set; } = true;

    public bool IncludeImageId { get; set; } = true;

    public bool IncludeImageName { get; set; } = true;

    public bool IncludeImageVersion { get; set; } = true;

    public bool IncludeName { get; set; } = true;

    public bool IncludeType { get; set; } = true;
    #endregion

    #region Opt-In (off by default)
    public bool IncludeIpAddress { get; set; }

    public bool IncludeMacAddress { get; set; }
    #endregion
}

@Kielek
Copy link
Contributor

Kielek commented Sep 20, 2024

@flaviocdc, could you please follow @CodeBlanch description? At least for already implemented resources?
Please update also README.md with example how to use this option.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp:resources.host Things related to OpenTelemetry.Resources.Host comp:resources.process Things related to OpenTelemetry.Resources.Process
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants