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

Exposing PropertyFetcher as a public API from OpenTelemetry package #1232

Merged
merged 7 commits into from
Sep 6, 2020
Merged

Exposing PropertyFetcher as a public API from OpenTelemetry package #1232

merged 7 commits into from
Sep 6, 2020

Conversation

eddynaka
Copy link
Contributor

@eddynaka eddynaka commented Sep 4, 2020

Fixes #1231.

Changes

Please provide a brief description of the changes here.

For significant contributions please make sure you have completed the following items:

  • CHANGELOG.md updated for non-trivial changes
  • Design discussion issue #
  • Changes in public API reviewed

@eddynaka eddynaka requested a review from a team September 4, 2020 14:10
@codecov
Copy link

codecov bot commented Sep 4, 2020

Codecov Report

Merging #1232 into master will decrease coverage by 0.04%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1232      +/-   ##
==========================================
- Coverage   78.93%   78.89%   -0.05%     
==========================================
  Files         219      215       -4     
  Lines        6347     6259      -88     
==========================================
- Hits         5010     4938      -72     
+ Misses       1337     1321      -16     
Impacted Files Coverage Δ
...c/OpenTelemetry/Instrumentation/PropertyFetcher.cs 86.95% <ø> (ø)
...tation.AspNetCore/Implementation/HttpInListener.cs 90.52% <100.00%> (ø)
...ent/Implementation/GrpcClientDiagnosticListener.cs 89.28% <100.00%> (ø)
...mentation/RedisProfilerEntryToActivityConverter.cs 94.59% <100.00%> (ø)
...us/Implementation/PrometheusExporterEventSource.cs 63.63% <0.00%> (-9.10%) ⬇️
...ter.ZPages/Implementation/ZPagesActivityTracker.cs 100.00% <0.00%> (+2.85%) ⬆️
...nTelemetry/Internal/OpenTelemetrySdkEventSource.cs 80.95% <0.00%> (+3.17%) ⬆️

@cijothomas
Copy link
Member

Add this to SDK changelog as a new adition to public API

@eddynaka
Copy link
Contributor Author

eddynaka commented Sep 4, 2020

Add this to SDK changelog as a new adition to public API

Just added

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

@reyang
Copy link
Member

reyang commented Sep 4, 2020

I understand that we want to reduce duplicated code.
Is this something that we can achieve by having a set of common files referenced by multiple projects?
Is there a strong reason to expose a public API?

For example, we already have these shared files:

    <Compile Include="$(RepoRoot)\src\OpenTelemetry.Api\Internal\ExceptionExtensions.cs" Link="Internal\ExceptionExtensions.cs" />
    <Compile Include="$(RepoRoot)\src\OpenTelemetry.Api\Trace\SemanticConventions.cs" />
    <Compile Include="$(RepoRoot)\src\OpenTelemetry\Internal\EnumerationHelper.cs" Link="Implementation\EnumerationHelper.cs" />

Copy link
Member

@reyang reyang left a comment

Choose a reason for hiding this comment

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

I'm concerned about exposing this as a public function.
We probably need to consider the file sharing approach.

@cijothomas
Copy link
Member

I understand that we want to reduce duplicated code.
Is this something that we can achieve by having a set of common files referenced by multiple projects?
Is there a strong reason to expose a public API?

For example, we already have these shared files:

    <Compile Include="$(RepoRoot)\src\OpenTelemetry.Api\Internal\ExceptionExtensions.cs" Link="Internal\ExceptionExtensions.cs" />
    <Compile Include="$(RepoRoot)\src\OpenTelemetry.Api\Trace\SemanticConventions.cs" />
    <Compile Include="$(RepoRoot)\src\OpenTelemetry\Internal\EnumerationHelper.cs" Link="Implementation\EnumerationHelper.cs" />

Avoiding code duplication is not the main reason for this PR. This allows anyone to write a new Instrumentation for DiagnosticSource instrumented libraries. (We already have the basic classes for subscription public, propertyfetcher is also required to fully enable on to write a instrumentation library))

@eddynaka
Copy link
Contributor Author

eddynaka commented Sep 4, 2020

I understand that we want to reduce duplicated code.
Is this something that we can achieve by having a set of common files referenced by multiple projects?
Is there a strong reason to expose a public API?
For example, we already have these shared files:

    <Compile Include="$(RepoRoot)\src\OpenTelemetry.Api\Internal\ExceptionExtensions.cs" Link="Internal\ExceptionExtensions.cs" />
    <Compile Include="$(RepoRoot)\src\OpenTelemetry.Api\Trace\SemanticConventions.cs" />
    <Compile Include="$(RepoRoot)\src\OpenTelemetry\Internal\EnumerationHelper.cs" Link="Implementation\EnumerationHelper.cs" />

Avoiding code duplication is not the main reason for this PR. This allows anyone to write a new Instrumentation for DiagnosticSource instrumented libraries. (We already have the basic classes for subscription public, propertyfetcher is also required to fully enable on to write a instrumentation library))

Should i move or should I maintain ?

@cijothomas
Copy link
Member

I understand that we want to reduce duplicated code.
Is this something that we can achieve by having a set of common files referenced by multiple projects?
Is there a strong reason to expose a public API?
For example, we already have these shared files:

    <Compile Include="$(RepoRoot)\src\OpenTelemetry.Api\Internal\ExceptionExtensions.cs" Link="Internal\ExceptionExtensions.cs" />
    <Compile Include="$(RepoRoot)\src\OpenTelemetry.Api\Trace\SemanticConventions.cs" />
    <Compile Include="$(RepoRoot)\src\OpenTelemetry\Internal\EnumerationHelper.cs" Link="Implementation\EnumerationHelper.cs" />

Avoiding code duplication is not the main reason for this PR. This allows anyone to write a new Instrumentation for DiagnosticSource instrumented libraries. (We already have the basic classes for subscription public, propertyfetcher is also required to fully enable on to write a instrumentation library))

Should i move or should I maintain ?

Please wait to hear Reiley's thoughts after I made clarification above about the intent of this PR.

The following class, along with propertyfetcher is public - so that anyone can write their own instrumentation for DiagnosticSource instrumented libraries.
https://github.com/open-telemetry/opentelemetry-dotnet/blob/master/src/OpenTelemetry/Instrumentation/ListenerHandler.cs

@reyang
Copy link
Member

reyang commented Sep 4, 2020

Avoiding code duplication is not the main reason for this PR. This allows anyone to write a new Instrumentation for DiagnosticSource instrumented libraries. (We already have the basic classes for subscription public, propertyfetcher is also required to fully enable on to write a instrumentation library))

Should i move or should I maintain ?

Please wait to hear Reiley's thoughts after I made clarification above about the intent of this PR.

The following class, along with propertyfetcher is public - so that anyone can write their own instrumentation for DiagnosticSource instrumented libraries.
https://github.com/open-telemetry/opentelemetry-dotnet/blob/master/src/OpenTelemetry/Instrumentation/ListenerHandler.cs

I'm fine with exposing a public API if the pros > cons.
I think we need to by crystal clear on the PR title (the title should reflect the intention) "why we are making the change", in this case it shouldn't be "Removing duplicated PropertyFetcher" and it might need to be "Exposing PropertyFetcher as a public API from OpenTelemetry package".

@reyang reyang self-requested a review September 4, 2020 17:02
@eddynaka eddynaka changed the title Removing duplicated PropertyFetcher Exposing PropertyFetcher as a public API from OpenTelemetry package Sep 4, 2020
@eddynaka
Copy link
Contributor Author

eddynaka commented Sep 4, 2020

Avoiding code duplication is not the main reason for this PR. This allows anyone to write a new Instrumentation for DiagnosticSource instrumented libraries. (We already have the basic classes for subscription public, propertyfetcher is also required to fully enable on to write a instrumentation library))

Should i move or should I maintain ?

Please wait to hear Reiley's thoughts after I made clarification above about the intent of this PR.
The following class, along with propertyfetcher is public - so that anyone can write their own instrumentation for DiagnosticSource instrumented libraries.
https://github.com/open-telemetry/opentelemetry-dotnet/blob/master/src/OpenTelemetry/Instrumentation/ListenerHandler.cs

I'm fine with exposing a public API if the pros > cons.
I think we need to by crystal clear on the PR title (the title should reflect the intention) "why we are making the change", in this case it shouldn't be "Removing duplicated PropertyFetcher" and it might need to be "Exposing PropertyFetcher as a public API from OpenTelemetry package".

just updated the title!

{
internal class PropertyFetcher
public class PropertyFetcher
Copy link
Member

Choose a reason for hiding this comment

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

nit: Should have XML comments now that it is public.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added some. not sure if the best text...

{
internal class PropertyFetcher
public class PropertyFetcher
Copy link
Member

Choose a reason for hiding this comment

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

I think we could improve this API. Internally it has a very nice, typed delegate created. But we only expose object Fetch(object) which basically throws away that typing information and will box any value types + require a cast. With a little work we could probably also expose:

class PropertyFetcher<TType, TPropertyType> : PropertyFetcher
{
   public TPropertyType Fetch(TType instance)
}

That would be useful when you know the types ahead of time, which is actually the more common case. It would allow us to avoid some of those performance penalties.

Let's merge this and then we can try to improve it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sounds great :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@CodeBlanch not sure how it was done originally, but inside the same class, we already have a typedPropertyFetcher. but, in the end, we are just returning as an object.

@lmolkova
Copy link

lmolkova commented Sep 4, 2020

I remember back in the day we discussed (in scope of DiagnosticSource work) that exposing efficient property fetching APIs may be reasonable in .NET.
cc @noahfalk @tarekgh

@CodeBlanch CodeBlanch merged commit d0d33ed into open-telemetry:master Sep 6, 2020
@CodeBlanch CodeBlanch mentioned this pull request Sep 6, 2020
3 tasks
@eddynaka eddynaka deleted the feature/removing-duplicated-code branch September 19, 2020 20:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make PropertyFetcher public and place it in OpenTelemetry.Api
6 participants