Skip to content

Commit 9bad19a

Browse files
TimPansinodependabot[bot]mergify[bot]lrafeeihmstepanek
authored
Merge main into develop-windows (#1474)
* Bump the github_actions group with 2 updates (#1466) Bumps the github_actions group with 2 updates: [codecov/codecov-action](https://github.com/codecov/codecov-action) and [github/codeql-action](https://github.com/github/codeql-action). Updates `codecov/codecov-action` from 5.4.3 to 5.5.0 - [Release notes](https://github.com/codecov/codecov-action/releases) - [Changelog](https://github.com/codecov/codecov-action/blob/main/CHANGELOG.md) - [Commits](codecov/codecov-action@18283e0...fdcc847) Updates `github/codeql-action` from 3.29.10 to 3.29.11 - [Release notes](https://github.com/github/codeql-action/releases) - [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md) - [Commits](github/codeql-action@96f518a...3c3833e) --- updated-dependencies: - dependency-name: codecov/codecov-action dependency-version: 5.5.0 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: github_actions - dependency-name: github/codeql-action dependency-version: 3.29.11 dependency-type: direct:production update-type: version-update:semver-patch dependency-group: github_actions ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> * Safeguards for deepest unique path (#1450) * Safeguards for deepest unique path * Remove breakpoint --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> * Add try-except to web request parsing (#1449) * Add try-except to web request parsing * Fix parsing logic * Add clarifying comment --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> * Use legacy bitnami for now (#1471) * Use legacy bitnami for now * Revert solr change * Revert zookeeper change * Add graphene-django instrumentation (#1451) * Add graphene-django instrumentation * Increase naming priority * Remove unused import * Add sychronous schema tests * Clean up test files * Remove commented out code * Megalinter fixes * Add operation & resolver tests * Refine tests * MegaLinter fixes * Suggested reviewer changes * Megalinter fixes * Django middleware filtering settings (#1444) * Reduce number of spans in django framework (#779) * Do not wrap useless middlewares * Fixup: use frozenset * Add config settings * Add middleware enable/disable options * Add testing * Testing exclude/include settings * Add optional fixture scope argument * Rewrite tests to use fixtures * Add new fixture * Fix tests * Fix ruff errors * MegaLinter Fixes * Add config file tests * MegaLinter fixes * Reviewer changes * MegaLinter fixes * Add InstrumentationMiddlewareSettings * More exclude/include filter tests * Megalinter fixes * Tests to increase coverage * Megalinter fixes * More coverage tests * ANOTHER TEST: --------- Co-authored-by: Hannah Stepanek <hstepanek@newrelic.com> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> * Pin bitnami images to bitnamilegacy (#1475) Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> * Distributed CI Image Build (#1478) * Distribute build of CI image across runners * Add weekly CI image rebuild * Add rust to toolchain * Add human readable job names * Linting --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> Co-authored-by: Lalleh Rafeei <84813886+lrafeei@users.noreply.github.com> Co-authored-by: Hannah Stepanek <hstepanek@newrelic.com>
1 parent 4616802 commit 9bad19a

29 files changed

+1759
-127
lines changed

.github/containers/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ RUN export DEBIAN_FRONTEND=noninteractive && \
5050
pkg-config \
5151
python3-dev \
5252
python3-pip \
53+
rustc \
5354
sudo \
5455
tzdata \
5556
unixodbc-dev \

.github/workflows/build-ci-image.yml

Lines changed: 100 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,31 @@ name: Build CI Image
1616

1717
on:
1818
workflow_dispatch: # Allow manual trigger
19+
schedule:
20+
- cron: "15 16 * * 0" # At 16:15 UTC on Sunday
1921

2022
permissions:
2123
contents: read
24+
packages: write
2225

2326
concurrency:
2427
group: ${{ github.ref || github.run_id }}
2528
cancel-in-progress: true
2629

2730
jobs:
2831
build:
29-
runs-on: ubuntu-24.04
32+
strategy:
33+
matrix:
34+
include:
35+
- platform: linux/amd64
36+
cache_tag: linux-amd64
37+
runner: ubuntu-24.04
38+
- platform: linux/arm64
39+
cache_tag: linux-arm64
40+
runner: ubuntu-24.04-arm
3041

31-
permissions:
32-
contents: read
33-
packages: write
42+
runs-on: ${{ matrix.runner }}
43+
name: Docker Build ${{ matrix.platform }}
3444

3545
steps:
3646
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # 5.0.0
@@ -42,11 +52,17 @@ jobs:
4252
id: buildx
4353
uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # 3.11.1
4454

55+
# Lowercase image name and append -ci
56+
- name: Generate Image Name
57+
id: image-name
58+
run: |
59+
echo "IMAGE_NAME=${GITHUB_REPOSITORY@L}-ci" >>"${GITHUB_OUTPUT}"
60+
4561
- name: Generate Docker Metadata (Tags and Labels)
4662
id: meta
4763
uses: docker/metadata-action@c1e51972afc2121e065aed6d45c65596fe445f3f # 5.8.0
4864
with:
49-
images: ghcr.io/${{ github.repository }}-ci
65+
images: ghcr.io/${{ steps.image-name.outputs.IMAGE_NAME }}
5066
flavor: |
5167
prefix=
5268
suffix=
@@ -65,11 +81,86 @@ jobs:
6581
username: ${{ github.repository_owner }}
6682
password: ${{ secrets.GITHUB_TOKEN }}
6783

68-
- name: Build and Publish Image
84+
- name: Build and Push Image by Digest
85+
id: build
6986
uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # 6.18.0
7087
with:
71-
push: ${{ github.event_name != 'pull_request' }}
7288
context: .github/containers
73-
platforms: ${{ (format('refs/heads/{0}', github.event.repository.default_branch) == github.ref) && 'linux/amd64,linux/arm64' || 'linux/amd64' }}
74-
tags: ${{ steps.meta.outputs.tags }}
89+
platforms: ${{ matrix.platform }}
7590
labels: ${{ steps.meta.outputs.labels }}
91+
outputs: type=image,name=ghcr.io/${{ steps.image-name.outputs.IMAGE_NAME }},push-by-digest=true,name-canonical=true,push=true
92+
cache-from: type=gha,scope=build-${{ matrix.cache_tag }}
93+
cache-to: type=gha,scope=build-${{ matrix.cache_tag }}
94+
95+
- name: Export Digest
96+
run: |
97+
mkdir -p ${{ runner.temp }}/digests
98+
digest="${{ steps.build.outputs.digest }}"
99+
touch "${{ runner.temp }}/digests/${digest#sha256:}"
100+
101+
- name: Upload Digest
102+
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # 4.6.2
103+
with:
104+
name: digests-${{ matrix.cache_tag }}
105+
path: ${{ runner.temp }}/digests/*
106+
if-no-files-found: error
107+
retention-days: 1
108+
109+
merge:
110+
runs-on: ubuntu-latest
111+
if: github.event_name != 'pull_request'
112+
needs:
113+
- build
114+
115+
name: Docker Merge Image
116+
117+
steps:
118+
- name: Download Digests
119+
uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # 5.0.0
120+
with:
121+
path: ${{ runner.temp }}/digests
122+
pattern: digests-*
123+
merge-multiple: true
124+
125+
- name: Login to GitHub Container Registry
126+
if: github.event_name != 'pull_request'
127+
uses: docker/login-action@184bdaa0721073962dff0199f1fb9940f07167d1 # 3.5.0
128+
with:
129+
registry: ghcr.io
130+
username: ${{ github.repository_owner }}
131+
password: ${{ secrets.GITHUB_TOKEN }}
132+
133+
- name: Set up Docker Buildx
134+
uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # 3.11.1
135+
136+
# Lowercase image name and append -ci
137+
- name: Generate Image Name
138+
id: image-name
139+
run: |
140+
echo "IMAGE_NAME=${GITHUB_REPOSITORY@L}-ci" >>"${GITHUB_OUTPUT}"
141+
142+
- name: Generate Docker Metadata (Tags and Labels)
143+
id: meta
144+
uses: docker/metadata-action@c1e51972afc2121e065aed6d45c65596fe445f3f # 5.8.0
145+
with:
146+
images: ghcr.io/${{ steps.image-name.outputs.IMAGE_NAME }}
147+
flavor: |
148+
prefix=
149+
suffix=
150+
latest=false
151+
tags: |
152+
type=raw,value=latest,enable={{is_default_branch}}
153+
type=schedule,pattern={{date 'YYYY-MM-DD'}}
154+
type=sha,format=short,prefix=sha-
155+
type=sha,format=long,prefix=sha-
156+
157+
- name: Create Manifest List and Push
158+
working-directory: ${{ runner.temp }}/digests
159+
run: |
160+
# shellcheck disable=SC2046
161+
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
162+
$(printf 'ghcr.io/${{ steps.image-name.outputs.IMAGE_NAME }}@sha256:%s ' *)
163+
164+
- name: Inspect Image
165+
run: |
166+
docker buildx imagetools inspect ghcr.io/${{ steps.image-name.outputs.IMAGE_NAME }}:${{ steps.meta.outputs.version }}

.github/workflows/tests.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ jobs:
108108
coverage xml
109109
110110
- name: Upload Coverage to Codecov
111-
uses: codecov/codecov-action@18283e04ce6e62d37312384ff67231eb8fd56d24 # 5.4.3
111+
uses: codecov/codecov-action@fdcc8476540edceab3de004e990f80d881c6cc00 # 5.5.0
112112
with:
113113
files: coverage.xml
114114
fail_ci_if_error: true
@@ -764,7 +764,7 @@ jobs:
764764
timeout-minutes: 30
765765
services:
766766
solr:
767-
image: bitnami/solr:8.8.2
767+
image: bitnamilegacy/solr:8.8.2
768768
env:
769769
SOLR_CORE: collection
770770
ports:
@@ -1026,15 +1026,15 @@ jobs:
10261026
timeout-minutes: 30
10271027
services:
10281028
zookeeper:
1029-
image: bitnami/zookeeper:3.9.1
1029+
image: bitnamilegacy/zookeeper:3.9.1
10301030
env:
10311031
ALLOW_ANONYMOUS_LOGIN: yes
10321032

10331033
ports:
10341034
- 2181:2181
10351035

10361036
kafka:
1037-
image: bitnami/kafka:3.6.1
1037+
image: bitnamilegacy/kafka:3.3.2
10381038
ports:
10391039
- 8080:8080
10401040
- 8082:8082

.github/workflows/trivy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,6 @@ jobs:
6161

6262
- name: Upload Trivy scan results to GitHub Security tab
6363
if: ${{ github.event_name == 'schedule' }}
64-
uses: github/codeql-action/upload-sarif@96f518a34f7a870018057716cc4d7a5c014bd61c # 3.29.10
64+
uses: github/codeql-action/upload-sarif@3c3833e0f8c1c83d449a7478aa59c036a9165498 # 3.29.11
6565
with:
6666
sarif_file: "trivy-results.sarif"

newrelic/api/web_transaction.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -665,13 +665,22 @@ def __init__(self, application, environ, source=None):
665665
self._request_uri = request_uri
666666

667667
if self._request_uri is not None:
668-
# Need to make sure we drop off any query string
669-
# arguments on the path if we have to fallback
670-
# to using the original REQUEST_URI. Can't use
671-
# attribute access on result as only support for
672-
# Python 2.5+.
673-
674-
self._request_uri = urlparse.urlparse(self._request_uri)[2]
668+
# This try/except logic is to handle cases where
669+
# `REQUEST_URI` is malformed or contains invalid
670+
# characters. This can happen at this point if
671+
# a malformed request is passed in and for versions
672+
# of `urllib` in the Python standard library older
673+
# than what has been released Jan 31, 2025.
674+
try:
675+
# Need to make sure we drop off any query string
676+
# arguments on the path if we have to fallback
677+
# to using the original REQUEST_URI. Can't use
678+
# attribute access on result as only support for
679+
# Python 2.5+.
680+
self._request_uri = urlparse.urlparse(self._request_uri)[2]
681+
except:
682+
# If `self._request_uri` is invalid, set to `None`
683+
self._request_uri = None
675684

676685
if script_name is not None or path_info is not None:
677686
if path_info is None:

newrelic/config.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,10 @@ def _map_inc_excl_attributes(s):
215215
return newrelic.core.config._parse_attributes(s)
216216

217217

218+
def _map_inc_excl_middleware(s):
219+
return newrelic.core.config._parse_attributes(s, middleware=True)
220+
221+
218222
def _map_case_insensitive_excl_labels(s):
219223
return [v.lower() for v in newrelic.core.config._parse_attributes(s)]
220224

@@ -510,6 +514,9 @@ def _process_configuration(section):
510514
section, "instrumentation.kombu.ignored_exchanges", "get", newrelic.core.config.parse_space_separated_into_list
511515
)
512516
_process_setting(section, "instrumentation.kombu.consumer.enabled", "getboolean", None)
517+
_process_setting(section, "instrumentation.middleware.django.enabled", "getboolean", None)
518+
_process_setting(section, "instrumentation.middleware.django.exclude", "get", _map_inc_excl_middleware)
519+
_process_setting(section, "instrumentation.middleware.django.include", "get", _map_inc_excl_middleware)
513520

514521

515522
# Loading of configuration from specified file and for specified
@@ -2701,6 +2708,10 @@ def _process_module_builtin_defaults():
27012708
"graphene.types.schema", "newrelic.hooks.framework_graphene", "instrument_graphene_types_schema"
27022709
)
27032710

2711+
_process_module_definition(
2712+
"graphene_django.views", "newrelic.hooks.component_graphenedjango", "instrument_graphene_django_views"
2713+
)
2714+
27042715
_process_module_definition("graphql.graphql", "newrelic.hooks.framework_graphql", "instrument_graphql")
27052716
_process_module_definition(
27062717
"graphql.execution.execute", "newrelic.hooks.framework_graphql", "instrument_graphql_execute"

newrelic/core/config.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,14 @@ class SpanEventAttributesSettings(Settings):
321321
pass
322322

323323

324+
class InstrumentationMiddlewareSettings(Settings):
325+
pass
326+
327+
328+
class InstrumentationDjangoMiddlewareSettings(Settings):
329+
pass
330+
331+
324332
class DistributedTracingSettings(Settings):
325333
pass
326334

@@ -508,6 +516,8 @@ class EventHarvestConfigHarvestLimitSettings(Settings):
508516
_settings.instrumentation.kombu = InstrumentationKombuSettings()
509517
_settings.instrumentation.kombu.ignored_exchanges = InstrumentationKombuIgnoredExchangesSettings()
510518
_settings.instrumentation.kombu.consumer = InstrumentationKombuConsumerSettings()
519+
_settings.instrumentation.middleware = InstrumentationMiddlewareSettings()
520+
_settings.instrumentation.middleware.django = InstrumentationDjangoMiddlewareSettings()
511521
_settings.message_tracer = MessageTracerSettings()
512522
_settings.process_host = ProcessHostSettings()
513523
_settings.rum = RumSettings()
@@ -635,11 +645,15 @@ def _parse_status_codes(value, target):
635645
return target
636646

637647

638-
def _parse_attributes(s):
648+
# Called from newrelic.config.py to parse
649+
# attributes and django middleware lists
650+
def _parse_attributes(s, middleware=False):
639651
valid = []
640652
for item in s.split():
641653
if "*" not in item[:-1] and len(item.encode("utf-8")) < 256:
642654
valid.append(item)
655+
elif middleware:
656+
_logger.warning("Improperly formatted middleware: %r", item)
643657
else:
644658
_logger.warning("Improperly formatted attribute: %r", item)
645659
return valid
@@ -905,6 +919,12 @@ def default_otlp_host(host):
905919
"NEW_RELIC_INSTRUMENTATION_KOMBU_CONSUMER_ENABLED", default=False
906920
)
907921

922+
_settings.instrumentation.middleware.django.enabled = _environ_as_bool(
923+
"NEW_RELIC_INSTRUMENTATION_DJANGO_MIDDLEWARE_ENABLED", default=True
924+
)
925+
_settings.instrumentation.middleware.django.exclude = []
926+
_settings.instrumentation.middleware.django.include = []
927+
908928
_settings.event_harvest_config.harvest_limits.analytic_event_data = _environ_as_int(
909929
"NEW_RELIC_ANALYTICS_EVENTS_MAX_SAMPLES_STORED", DEFAULT_RESERVOIR_SIZE
910930
)

0 commit comments

Comments
 (0)