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

Modify ElasticSearch Instrumentation to take advantage of sampling decision #95

Conversation

utpilla
Copy link
Contributor

@utpilla utpilla commented Mar 17, 2021

Extends the optimization done in PR #1894 to optimize ElasticSearch Instrumentation

Changes

  • Added a check to return from the OnStartActivity method of the listener if the instrumentation is suppressed
  • Wrap the logic in OnStartActivity to perform operations such as fetch uri, set the activity DisplayName, etc. only when - activity.IsAllDataRequested is set to true
  • Added unit tests to check if the instrumentation respects Sdk.SuppressInstrumentation and activity.IsAllDataRequested

@utpilla utpilla requested a review from a team March 17, 2021 19:54
@codecov
Copy link

codecov bot commented Mar 17, 2021

Codecov Report

Merging #95 (d633ae4) into main (826d77b) will not change coverage.
The diff coverage is 80.00%.

❗ Current head d633ae4 differs from pull request most recent head a6b919f. Consider uploading reports for the commit a6b919f to get more accurate results
Impacted file tree graph

@@           Coverage Diff           @@
##             main      #95   +/-   ##
=======================================
  Coverage   77.51%   77.51%           
=======================================
  Files          52       52           
  Lines        1454     1454           
=======================================
  Hits         1127     1127           
  Misses        327      327           
Impacted Files Coverage Δ
.../ElasticsearchRequestPipelineDiagnosticListener.cs 82.35% <80.00%> (ø)

activity.SetTag(SemanticConventions.AttributeDbName, elasticIndex);
}
var elasticIndex = this.GetElasticIndex(uri);
activity.DisplayName = this.GetDisplayName(activity, method, elasticIndex);
Copy link
Member

Choose a reason for hiding this comment

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

DisplayName was already set few lines above. One of them could be removed

Copy link
Contributor

Choose a reason for hiding this comment

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

The reason it was set above was because that used to be outside of the check for IsAllDataRequested and gave the activity a basic display name and if IsAllDataRequested was true it set it to a more details display name.

@cijothomas
Copy link
Member

@ejsmith Would you be willing to put yourself as a codeowner for this ES instrumentation, and review/approve the PRs?

@ejsmith
Copy link
Contributor

ejsmith commented Mar 19, 2021

@ejsmith Would you be willing to put yourself as a codeowner for this ES instrumentation, and review/approve the PRs?

Yeah, that would be good with me.

return;
}

ActivityInstrumentationHelper.SetActivitySourceProperty(activity, ActivitySource);
ActivityInstrumentationHelper.SetKindProperty(activity, ActivityKind.Client);
if (activity.IsAllDataRequested)
Copy link
Contributor

Choose a reason for hiding this comment

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

Previously, we were doing some things even when IsAllDataRequested was false. Is it best practice now to not do anything?

Copy link
Contributor

Choose a reason for hiding this comment

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

I see that other instrumentations like the HTTP one are still gathering some info even when IsAllDataRequested is false. But this PR is changing it so that we don't do anything. I'm concerned that by removing the basic level of information that the activity spans will be so generic you won't know what they are for.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If IsAllDataRequested is set to false, we don't export the activity as Processor.OnEnd is not called. So it wouldn't really be an issue if the activity doesn't have that basic level of information as it would never be sent to Processors.

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

HTTP instrumentation does not enrich the activity if IsAllDataRequested is set to false. It only propagates context as we don't want broken traces. If HTTP instrumentation does not propagate context, then the external system which receives the HTTP call will create new TraceId for the same transaction, and this will lead to broken traces. That's why, we ensure that the context is propagated regardless of the sampling decision as the other system that is receiving the HTTP call might upsample the activity and export it. In that case, we want to retain the same TraceId for that operation.

In case of Elasticsearch, there is no context propagation happening. We only enrich the activity, which wouldn't be necessary if we are not going to export that activity.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, that makes sense. Guess we would just need to de-duplicate the DisplayName setting then.

Copy link
Contributor

@ejsmith ejsmith left a comment

Choose a reason for hiding this comment

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

LGTM

@cijothomas cijothomas merged commit 8906aae into open-telemetry:main Mar 24, 2021
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.

3 participants