Skip to content

Commit a869322

Browse files
authored
Merge branch 'main' into feat/file-exporter
2 parents 68dfd7f + 1731583 commit a869322

16 files changed

Lines changed: 237 additions & 49 deletions

File tree

.changelog/5075.fixed

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
`opentelemetry-sdk`: Allow declarative OTLP HTTP exporters to map `compression: deflate` instead of rejecting it as unsupported.

.github/workflows/changelog.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ on:
99
types: [opened, synchronize, reopened, labeled, unlabeled]
1010
branches:
1111
- main
12+
merge_group:
1213

1314
permissions:
1415
contents: read
@@ -17,6 +18,7 @@ jobs:
1718
changelog:
1819
runs-on: ubuntu-latest
1920
if: |
21+
github.event_name != 'merge_group' &&
2022
!contains(github.event.pull_request.labels.*.name, 'Skip Changelog')
2123
&& github.actor != 'otelbot[bot]'
2224
@@ -56,5 +58,30 @@ jobs:
5658
false
5759
fi
5860
61+
- name: Validate fragment filenames
62+
env:
63+
PR_NUMBER: ${{ github.event.pull_request.number }}
64+
run: |
65+
fragments=$(git diff --diff-filter=A --name-only origin/${{ github.base_ref }} -- '.changelog/*' | grep -v '/\.gitignore$' || true)
66+
[ -z "$fragments" ] && exit 0
67+
invalid=()
68+
while IFS= read -r f; do
69+
base=$(basename "$f")
70+
if [[ ! "$base" =~ ^([0-9]+)\.(added|changed|deprecated|removed|fixed)$ ]]; then
71+
invalid+=("$f (expected <PR_NUMBER>.<type>; type one of added, changed, deprecated, removed, fixed)")
72+
continue
73+
fi
74+
if [[ "${BASH_REMATCH[1]}" != "${PR_NUMBER}" ]]; then
75+
invalid+=("$f (PR number ${BASH_REMATCH[1]} does not match this PR's number ${PR_NUMBER})")
76+
fi
77+
done <<< "$fragments"
78+
if (( ${#invalid[@]} > 0 )); then
79+
echo "Invalid changelog fragment(s):"
80+
for msg in "${invalid[@]}"; do
81+
echo " $msg"
82+
done
83+
exit 1
84+
fi
85+
5986
- name: Preview changelog
6087
run: towncrier build --draft --version Unreleased

.github/workflows/check-links.yml

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,24 @@ on:
1313
- '**/*.rst'
1414
- '.github/workflows/check-links.yml'
1515
- '.github/workflows/check_links_config.json'
16+
merge_group:
17+
paths:
18+
- '**/*.md'
19+
- '**/*.rst'
20+
- '.github/workflows/check-links.yml'
21+
- '.github/workflows/check_links_config.json'
1622

1723
permissions:
1824
contents: read
1925

2026
concurrency:
21-
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.run_id }}
27+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.event.merge_group.head_sha || github.run_id }}
2228
cancel-in-progress: true
2329

30+
env:
31+
# Diff against merge group SHAs in queue, or PR base branch otherwise
32+
DIFF_RANGE: ${{ github.event_name == 'merge_group' && format('{0}...{1}', github.event.merge_group.base_sha, github.event.merge_group.head_sha) || format('origin/{0}...HEAD', github.base_ref) }}
33+
2434
jobs:
2535
check-links:
2636
runs-on: ubuntu-latest
@@ -53,14 +63,14 @@ jobs:
5363
${{ steps.changed-files.outputs.all_changed_files }} \
5464
|| { echo "Check that anchor links are lowercase"; exit 1; }
5565
56-
- name: Check new links only on pull requests
57-
if: steps.changed-files.outputs.any_changed == 'true' && github.event_name == 'pull_request'
66+
- name: Check new links only on pull requests and merge groups
67+
if: steps.changed-files.outputs.any_changed == 'true' && (github.event_name == 'pull_request' || github.event_name == 'merge_group')
5868
run: |
5969
# Extract URLs only from added lines in the diff to avoid
6070
# rate limiting when checking all links in large files like
6171
# CHANGELOG.md. Only new/changed links are checked on PRs;
6272
# pushes to main still check all links in changed files.
63-
git diff "origin/${{ github.base_ref }}...HEAD" -- \
73+
git diff "$DIFF_RANGE" -- \
6474
${{ steps.changed-files.outputs.all_changed_files }} \
6575
| grep '^+' | grep -v '^+++' \
6676
| grep -oP 'https?://[^\s\)\]\"'"'"'`>]+' \

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ on:
88
branches:
99
- 'main'
1010
pull_request:
11+
merge_group:
1112

1213
permissions:
1314
contents: read

.github/workflows/misc.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,9 @@ jobs:
9898
runs-on: ubuntu-latest
9999
timeout-minutes: 30
100100
if: |
101-
github.event.pull_request.user.login != 'otelbot[bot]' && github.event_name == 'pull_request'
101+
github.event_name == 'merge_group' ||
102+
(github.event_name == 'pull_request' &&
103+
github.event.pull_request.user.login != 'otelbot[bot]')
102104
steps:
103105
- name: Checkout repo @ SHA - ${{ github.sha }}
104106
uses: actions/checkout@v4

.github/workflows/templates/ci.yml.j2

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ on:
88
branches:
99
- 'main'
1010
pull_request:
11+
merge_group:
1112

1213
permissions:
1314
contents: read

.github/workflows/templates/misc.yml.j2

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ jobs:
4646
{%- endif %}
4747
{%- if job_data == "docs" %}
4848
if: |
49-
github.event.pull_request.user.login != 'otelbot[bot]' && github.event_name == 'pull_request'
49+
github.event_name == 'merge_group' ||
50+
(github.event_name == 'pull_request' &&
51+
github.event.pull_request.user.login != 'otelbot[bot]')
5052
{%- endif %}
5153
steps:
5254
- name: Checkout repo @ SHA - ${% raw %}{{ github.sha }}{% endraw %}

opentelemetry-sdk/src/opentelemetry/sdk/_configuration/_common.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,33 @@ def _parse_headers(
102102
else:
103103
result[pair.name] = pair.value or ""
104104
return result
105+
106+
107+
def _map_compression(
108+
value: str | None,
109+
compression_enum: type,
110+
*,
111+
allow_deflate: bool = False,
112+
) -> object | None:
113+
"""Map a compression string to the given Compression enum value."""
114+
if value is None:
115+
return None
116+
117+
value_lower = value.lower()
118+
supports_deflate = hasattr(compression_enum, "Deflate")
119+
120+
if value_lower == "none":
121+
return None
122+
if value_lower == "gzip":
123+
return compression_enum.Gzip # type: ignore[attr-defined]
124+
if value_lower == "deflate" and allow_deflate and supports_deflate:
125+
return compression_enum.Deflate # type: ignore[attr-defined]
126+
127+
supported_values = ["'gzip'", "'none'"]
128+
if allow_deflate and supports_deflate:
129+
supported_values.insert(1, "'deflate'")
130+
131+
raise ConfigurationError(
132+
f"Unsupported compression value '{value}'. Supported values: "
133+
f"{', '.join(supported_values)}."
134+
)

opentelemetry-sdk/src/opentelemetry/sdk/_configuration/_logger_provider.py

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
from opentelemetry._logs import set_logger_provider
99
from opentelemetry.sdk._configuration._common import (
10+
_map_compression,
1011
_parse_headers,
1112
load_entry_point,
1213
)
@@ -50,19 +51,6 @@
5051
_DEFAULT_MAX_EXPORT_BATCH_SIZE = 512
5152

5253

53-
def _map_compression(
54-
value: str | None, compression_enum: type
55-
) -> object | None:
56-
"""Map a compression string to the given Compression enum value."""
57-
if value is None or value.lower() == "none":
58-
return None
59-
if value.lower() == "gzip":
60-
return compression_enum.Gzip # type: ignore[attr-defined]
61-
raise ConfigurationError(
62-
f"Unsupported compression value '{value}'. Supported values: 'gzip', 'none'."
63-
)
64-
65-
6654
def _create_console_log_exporter() -> ConsoleLogRecordExporter:
6755
"""Create a ConsoleLogRecordExporter."""
6856
return ConsoleLogRecordExporter()
@@ -86,7 +74,9 @@ def _create_otlp_http_log_exporter(
8674
"Install it with: pip install opentelemetry-exporter-otlp-proto-http"
8775
) from exc
8876

89-
compression = _map_compression(config.compression, Compression)
77+
compression = _map_compression(
78+
config.compression, Compression, allow_deflate=True
79+
)
9080
headers = _parse_headers(config.headers, config.headers_list)
9181
timeout = (config.timeout / 1000.0) if config.timeout is not None else None
9282

opentelemetry-sdk/src/opentelemetry/sdk/_configuration/_meter_provider.py

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
from opentelemetry import metrics
99
from opentelemetry.sdk._configuration._common import (
10+
_map_compression,
1011
_parse_headers,
1112
load_entry_point,
1213
)
@@ -256,19 +257,6 @@ def _create_console_metric_exporter(
256257
)
257258

258259

259-
def _map_compression_metric(
260-
value: str | None, compression_enum: type
261-
) -> object | None:
262-
"""Map a compression string to the given Compression enum value."""
263-
if value is None or value.lower() == "none":
264-
return None
265-
if value.lower() == "gzip":
266-
return compression_enum.Gzip # type: ignore[attr-defined]
267-
raise ConfigurationError(
268-
f"Unsupported compression value '{value}'. Supported values: 'gzip', 'none'."
269-
)
270-
271-
272260
def _create_otlp_http_metric_exporter(
273261
config: OtlpHttpMetricExporterConfig,
274262
) -> MetricExporter:
@@ -287,7 +275,9 @@ def _create_otlp_http_metric_exporter(
287275
"Install it with: pip install opentelemetry-exporter-otlp-proto-http"
288276
) from exc
289277

290-
compression = _map_compression_metric(config.compression, Compression)
278+
compression = _map_compression(
279+
config.compression, Compression, allow_deflate=True
280+
)
291281
headers = _parse_headers(config.headers, config.headers_list)
292282
timeout = (config.timeout / 1000.0) if config.timeout is not None else None
293283
preferred_temporality = _map_temporality(config.temporality_preference)
@@ -322,7 +312,7 @@ def _create_otlp_grpc_metric_exporter(
322312
"Install it with: pip install opentelemetry-exporter-otlp-proto-grpc"
323313
) from exc
324314

325-
compression = _map_compression_metric(config.compression, grpc.Compression)
315+
compression = _map_compression(config.compression, grpc.Compression)
326316
headers = _parse_headers(config.headers, config.headers_list)
327317
timeout = (config.timeout / 1000.0) if config.timeout is not None else None
328318
preferred_temporality = _map_temporality(config.temporality_preference)

0 commit comments

Comments
 (0)