-
Notifications
You must be signed in to change notification settings - Fork 567
Feature/span limits #816
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
Feature/span limits #816
Changes from all commits
893aba4
249ad35
db79ada
3f14a59
d7b39fe
179838f
5f916bf
a35cc8c
41c05dc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,119 @@ | ||
| // Copyright 2021, OpenTelemetry Authors | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| #pragma once | ||
| #include "opentelemetry/common/spin_lock_mutex.h" | ||
| #include "opentelemetry/nostd/shared_ptr.h" | ||
| #include "opentelemetry/version.h" | ||
|
|
||
| OPENTELEMETRY_BEGIN_NAMESPACE | ||
| namespace sdk | ||
| { | ||
| namespace trace | ||
| { | ||
| /** | ||
| * Collection of span limits configurations. | ||
| */ | ||
| class SpanLimits | ||
| { | ||
| public: | ||
| /** | ||
| * Setter methods of configuration params | ||
| */ | ||
| static void SetAttributeCountLimit(int attributeCountLimit) | ||
| { | ||
| std::lock_guard<opentelemetry::common::SpinLockMutex> guard(GetLock()); | ||
| GetSpanLimits()->AttributeCountLimit = attributeCountLimit; | ||
| } | ||
|
|
||
| static void SetEventCountLimit(int eventCountLimit) | ||
| { | ||
| std::lock_guard<opentelemetry::common::SpinLockMutex> guard(GetLock()); | ||
| GetSpanLimits()->EventCountLimit = eventCountLimit; | ||
| } | ||
|
|
||
| static void SetLinkCountLimit(int linkCountLimit) | ||
| { | ||
| std::lock_guard<opentelemetry::common::SpinLockMutex> guard(GetLock()); | ||
| GetSpanLimits()->LinkCountLimit = linkCountLimit; | ||
| } | ||
|
|
||
| static void SetAttributePerEventCountLimit(int attributePerEventCountLimit) | ||
| { | ||
| std::lock_guard<opentelemetry::common::SpinLockMutex> guard(GetLock()); | ||
| GetSpanLimits()->AttributePerEventCountLimit = attributePerEventCountLimit; | ||
| } | ||
|
|
||
| static void SetAttributePerLinkCountLimit(int attributePerLinkCountLimit) | ||
| { | ||
| std::lock_guard<opentelemetry::common::SpinLockMutex> guard(GetLock()); | ||
| GetSpanLimits()->AttributePerLinkCountLimit = attributePerLinkCountLimit; | ||
| } | ||
|
|
||
| /** | ||
| * Getter methods of configuration params | ||
| */ | ||
| static int GetAttributeCountLimit() | ||
| { | ||
| std::lock_guard<opentelemetry::common::SpinLockMutex> guard(GetLock()); | ||
| return GetSpanLimits()->AttributeCountLimit; | ||
| } | ||
|
|
||
| static int GetEventCountLimit() | ||
| { | ||
| std::lock_guard<opentelemetry::common::SpinLockMutex> guard(GetLock()); | ||
| return GetSpanLimits()->EventCountLimit; | ||
| } | ||
|
|
||
| static int GetLinkCountLimit() | ||
| { | ||
| std::lock_guard<opentelemetry::common::SpinLockMutex> guard(GetLock()); | ||
| return GetSpanLimits()->LinkCountLimit; | ||
| } | ||
|
|
||
| static int GetAttributePerEventCountLimit() | ||
| { | ||
| std::lock_guard<opentelemetry::common::SpinLockMutex> guard(GetLock()); | ||
| return GetSpanLimits()->AttributePerEventCountLimit; | ||
| } | ||
|
|
||
| static int GetAttributePerLinkCountLimit() | ||
| { | ||
| std::lock_guard<opentelemetry::common::SpinLockMutex> guard(GetLock()); | ||
| return GetSpanLimits()->AttributePerLinkCountLimit; | ||
| } | ||
|
|
||
| private: | ||
| static nostd::shared_ptr<SpanLimits> &GetSpanLimits() noexcept | ||
| { | ||
| static nostd::shared_ptr<SpanLimits> spanLimits(new SpanLimits); | ||
| return spanLimits; | ||
| } | ||
|
|
||
| static opentelemetry::common::SpinLockMutex &GetLock() noexcept | ||
| { | ||
| static opentelemetry::common::SpinLockMutex lock; | ||
| return lock; | ||
| } | ||
|
|
||
| int AttributeCountLimit = 128; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry for naïve question :
Apologies if it's a dumb question.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Spec mentions these limits set to tracer provider and we have one global tracer provider, so in the current scenario all of these limits should be same. |
||
| int EventCountLimit = 128; | ||
| int LinkCountLimit = 128; | ||
| int AttributePerEventCountLimit = 128; | ||
| int AttributePerLinkCountLimit = 128; | ||
| }; | ||
| } // namespace trace | ||
| } // namespace sdk | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can this be a class with static methods to return the limits?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since we are having a global tracer provider and span limits are associated with that only, so that should be better as it will simplify arguments passing. Will make the changes in next commit. |
||
| OPENTELEMETRY_END_NAMESPACE | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if this is a good idea to drop the attributes silently.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed.
We can either log every time when attribute is dropped, but that would be excessive logging and is not recommended in the spec.
Second way, we can store the information of how many attributes are added in the span and so the number of attributes dropped. This should be enough information, any opinion on this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, this won't really work... Because I'd see that class being used not necessarily only for Span Attributes. But for Resource Attributes as well. Do resource attributes have the same limit? I mean - can we move this check elsewhere.. Can we keep it a generic converter-helper class to transform attributes from API AttributeValue to OwnedAttributeValue, and just keep it as generic as possible, without binding it to Span specifics.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The limit is specific to Span attributes, links, and events. SDK doesn't own/copy any of these properties internally, so it is not possible to impose this limit within sdk. All these properties are propagated to exporters, and it is up to the exporters to impose the limits. The exporters may choose not to transform these properties to
OwnedAttributeValueand instead transform/serialize to (say) JSON format for performance reasons.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lalitb - I think we should have that trigger (limit enforcement) somewhere when we transform into
OwnedAttributeValue. I don't have concrete proposals. Maybe we should merge the foundation class for some enforcement, proposed here in this PR. Then find out a good way to bind to that class.