Skip to content

Commit 9c93606

Browse files
committed
Merge branch 'main' into dluna-ci-pr-speed-and-coverage
2 parents 0896c53 + 3263936 commit 9c93606

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+3525
-3246
lines changed

.github/ISSUE_TEMPLATE/bug_report.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,4 @@ If possible, provide a recipe for reproducing the error.
3131
Add any other context about the problem here.
3232
-->
3333

34+
<sub>**Tip**: [React](https://github.blog/news-insights/product-news/add-reactions-to-pull-requests-issues-and-comments/) with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding `+1` or `me too`, to help us triage it. Learn more [here](https://opentelemetry.io/community/end-user/issue-participation/).</sub>

.github/ISSUE_TEMPLATE/discussion.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,5 @@ labels: discussion
1111
- [ ] This only affects the JavaScript OpenTelemetry library
1212
- [ ] This may affect other libraries, but I would like to get opinions here first
1313

14+
<sub>**Tip**: [React](https://github.blog/news-insights/product-news/add-reactions-to-pull-requests-issues-and-comments/) with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding `+1` or `me too`, to help us triage it. Learn more [here](https://opentelemetry.io/community/end-user/issue-participation/).</sub>
15+

.github/ISSUE_TEMPLATE/feature_request.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,5 @@ A clear and concise description of any alternative solutions or features you've
3131
Add any other context or screenshots about the feature request here.
3232
-->
3333

34+
<sub>**Tip**: [React](https://github.blog/news-insights/product-news/add-reactions-to-pull-requests-issues-and-comments/) with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding `+1` or `me too`, to help us triage it. Learn more [here](https://opentelemetry.io/community/end-user/issue-participation/).</sub>
35+

.github/ISSUE_TEMPLATE/instrumentation_request.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,5 @@ Any code-owners listed MUST fulfill all criteria laid out in the checklist below
3434
<!--
3535
Add any other context or screenshots about the instrumentation request here. Is there a reference you could point for the well-defined lifecycle methods?
3636
-->
37+
38+
<sub>**Tip**: [React](https://github.blog/news-insights/product-news/add-reactions-to-pull-requests-issues-and-comments/) with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding `+1` or `me too`, to help us triage it. Learn more [here](https://opentelemetry.io/community/end-user/issue-participation/).</sub>

.github/ISSUE_TEMPLATE/ownership_request.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,5 @@ Examples:
3838
<!--
3939
Add any other context that does not fit any of the above sections
4040
-->
41+
42+
<sub>**Tip**: [React](https://github.blog/news-insights/product-news/add-reactions-to-pull-requests-issues-and-comments/) with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding `+1` or `me too`, to help us triage it. Learn more [here](https://opentelemetry.io/community/end-user/issue-participation/).</sub>

.release-please-manifest.json

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"packages/resource-detector-github": "0.31.0",
88
"packages/resource-detector-instana": "0.22.0",
99
"packages/auto-configuration-propagators": "0.4.1",
10-
"packages/auto-instrumentations-node": "0.62.0",
10+
"packages/auto-instrumentations-node": "0.62.1",
1111
"packages/auto-instrumentations-web": "0.49.0",
1212
"packages/baggage-span-processor": "0.4.0",
1313
"packages/baggage-log-record-processor": "0.4.0",
@@ -17,21 +17,21 @@
1717
"packages/redis-common": "0.38.0",
1818
"packages/sql-common": "0.41.0",
1919
"packages/contrib-test-utils": "0.49.0",
20-
"packages/winston-transport": "0.14.0",
20+
"packages/winston-transport": "0.14.1",
2121
"packages/instrumentation-amqplib": "0.50.0",
22-
"packages/instrumentation-cucumber": "0.18.0",
23-
"packages/instrumentation-dataloader": "0.21.0",
22+
"packages/instrumentation-cucumber": "0.18.1",
23+
"packages/instrumentation-dataloader": "0.21.1",
2424
"packages/instrumentation-fs": "0.23.0",
25-
"packages/instrumentation-kafkajs": "0.12.0",
25+
"packages/instrumentation-kafkajs": "0.13.0",
2626
"packages/instrumentation-lru-memoizer": "0.48.0",
2727
"packages/instrumentation-mongoose": "0.50.0",
28-
"packages/instrumentation-runtime-node": "0.17.0",
28+
"packages/instrumentation-runtime-node": "0.17.1",
2929
"packages/instrumentation-socket.io": "0.50.0",
3030
"packages/instrumentation-tedious": "0.22.0",
3131
"packages/instrumentation-typeorm": "0.4.0",
3232
"packages/instrumentation-undici": "0.14.0",
3333
"packages/instrumentation-aws-lambda": "0.54.0",
34-
"packages/instrumentation-aws-sdk": "0.56.0",
34+
"packages/instrumentation-aws-sdk": "0.57.0",
3535
"packages/instrumentation-bunyan": "0.49.0",
3636
"packages/instrumentation-cassandra-driver": "0.49.0",
3737
"packages/instrumentation-connect": "0.47.0",
@@ -47,16 +47,16 @@
4747
"packages/instrumentation-memcached": "0.47.0",
4848
"packages/instrumentation-mongodb": "0.56.0",
4949
"packages/instrumentation-mysql": "0.49.0",
50-
"packages/instrumentation-mysql2": "0.49.0",
50+
"packages/instrumentation-mysql2": "0.50.0",
5151
"packages/instrumentation-nestjs-core": "0.49.0",
5252
"packages/instrumentation-net": "0.47.0",
5353
"packages/instrumentation-oracledb": "0.29.0",
54-
"packages/instrumentation-pg": "0.55.0",
54+
"packages/instrumentation-pg": "0.56.0",
5555
"packages/instrumentation-pino": "0.50.0",
5656
"packages/instrumentation-redis": "0.51.0",
5757
"packages/instrumentation-restify": "0.49.0",
5858
"packages/instrumentation-router": "0.48.0",
59-
"packages/instrumentation-winston": "0.48.0",
59+
"packages/instrumentation-winston": "0.48.1",
6060
"packages/instrumentation-document-load": "0.48.0",
6161
"packages/instrumentation-long-task": "0.48.0",
6262
"packages/instrumentation-user-interaction": "0.48.0",

incubator/opentelemetry-sampler-aws-xray/src/aws-xray-sampling-client.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export class AWSXRaySamplingClient {
4545
this.makeSamplingRequest<GetSamplingTargetsResponse>(
4646
this.samplingTargetsEndpoint,
4747
callback,
48-
this.samplerDiag.debug,
48+
(message: string) => this.samplerDiag.debug(message),
4949
JSON.stringify(requestBody)
5050
);
5151
}
@@ -56,7 +56,7 @@ export class AWSXRaySamplingClient {
5656
this.makeSamplingRequest<GetSamplingRulesResponse>(
5757
this.getSamplingRulesEndpoint,
5858
callback,
59-
this.samplerDiag.error
59+
(message: string) => this.samplerDiag.error(message)
6060
);
6161
}
6262

incubator/opentelemetry-sampler-aws-xray/src/fallback-sampler.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,20 @@
2121
import { Attributes, Context, Link, SpanKind } from '@opentelemetry/api';
2222
import {
2323
Sampler,
24+
SamplingDecision,
2425
SamplingResult,
2526
TraceIdRatioBasedSampler,
2627
} from '@opentelemetry/sdk-trace-base';
28+
import { RateLimitingSampler } from './rate-limiting-sampler';
2729

2830
// FallbackSampler samples 1 req/sec and additional 5% of requests using TraceIdRatioBasedSampler.
2931
export class FallbackSampler implements Sampler {
3032
private fixedRateSampler: TraceIdRatioBasedSampler;
33+
private rateLimitingSampler: RateLimitingSampler;
3134

32-
constructor() {
33-
this.fixedRateSampler = new TraceIdRatioBasedSampler(0.05);
35+
constructor(ratio = 0.05, quota = 1) {
36+
this.fixedRateSampler = new TraceIdRatioBasedSampler(ratio);
37+
this.rateLimitingSampler = new RateLimitingSampler(quota);
3438
}
3539

3640
shouldSample(
@@ -41,7 +45,19 @@ export class FallbackSampler implements Sampler {
4145
attributes: Attributes,
4246
links: Link[]
4347
): SamplingResult {
44-
// TODO: implement and use Rate Limiting Sampler
48+
const samplingResult: SamplingResult =
49+
this.rateLimitingSampler.shouldSample(
50+
context,
51+
traceId,
52+
spanName,
53+
spanKind,
54+
attributes,
55+
links
56+
);
57+
58+
if (samplingResult.decision !== SamplingDecision.NOT_RECORD) {
59+
return samplingResult;
60+
}
4561

4662
return this.fixedRateSampler.shouldSample(context, traceId);
4763
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
// Includes work from:
18+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
19+
// SPDX-License-Identifier: Apache-2.0
20+
21+
/*
22+
* The RateLimiter keeps track of the current reservoir quota balance available (measured via available time)
23+
* If enough time has elapsed, the RateLimiter will allow quota balance to be consumed/taken (decrease available time)
24+
* A RateLimitingSampler uses this RateLimiter to determine if it should sample or not based on the quota balance available.
25+
*/
26+
export class RateLimiter {
27+
// Quota assigned to client to dictate maximum quota balance that can be consumed per second.
28+
private quota: number;
29+
private MAX_BALANCE_MILLIS: number;
30+
// Used to measure current quota balance.
31+
private walletFloorMillis: number;
32+
33+
constructor(quota: number, maxBalanceInSeconds = 1) {
34+
this.MAX_BALANCE_MILLIS = maxBalanceInSeconds * 1000.0;
35+
this.quota = quota;
36+
this.walletFloorMillis = Date.now();
37+
// current "balance" would be `ceiling - floor`
38+
}
39+
40+
public take(cost = 1): boolean {
41+
if (this.quota === 0) {
42+
return false;
43+
}
44+
45+
// assume divide by zero not possible
46+
const costInMillis: number = (cost * 1000.0) / this.quota;
47+
48+
const walletCeilingMillis: number = Date.now();
49+
let currentBalanceMillis: number =
50+
walletCeilingMillis - this.walletFloorMillis;
51+
currentBalanceMillis = Math.min(
52+
currentBalanceMillis,
53+
this.MAX_BALANCE_MILLIS
54+
);
55+
const pendingRemainingBalanceMillis: number =
56+
currentBalanceMillis - costInMillis;
57+
if (pendingRemainingBalanceMillis >= 0) {
58+
this.walletFloorMillis =
59+
walletCeilingMillis - pendingRemainingBalanceMillis;
60+
return true;
61+
}
62+
// No changes to the wallet state
63+
return false;
64+
}
65+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
// Includes work from:
18+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
19+
// SPDX-License-Identifier: Apache-2.0
20+
21+
import { Attributes, Context, Link, SpanKind } from '@opentelemetry/api';
22+
import {
23+
Sampler,
24+
SamplingDecision,
25+
SamplingResult,
26+
} from '@opentelemetry/sdk-trace-base';
27+
import { RateLimiter } from './rate-limiter';
28+
29+
export class RateLimitingSampler implements Sampler {
30+
private quota: number;
31+
private reservoir: RateLimiter;
32+
33+
constructor(quota: number) {
34+
this.quota = quota;
35+
this.reservoir = new RateLimiter(quota);
36+
}
37+
38+
shouldSample(
39+
context: Context,
40+
traceId: string,
41+
spanName: string,
42+
spanKind: SpanKind,
43+
attributes: Attributes,
44+
links: Link[]
45+
): SamplingResult {
46+
if (this.reservoir.take(1)) {
47+
return {
48+
decision: SamplingDecision.RECORD_AND_SAMPLED,
49+
attributes: attributes,
50+
};
51+
}
52+
return { decision: SamplingDecision.NOT_RECORD, attributes: attributes };
53+
}
54+
55+
public toString(): string {
56+
return `RateLimitingSampler{rate limiting sampling with sampling config of ${this.quota} req/sec and 0% of additional requests}`;
57+
}
58+
}

0 commit comments

Comments
 (0)