Skip to content

Commit 4d62edf

Browse files
committed
PHP agent extension injection Logic
1 parent 00af38b commit 4d62edf

47 files changed

Lines changed: 610 additions & 48 deletions

Some content is hidden

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

.github/workflows/publish-images.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ jobs:
2424
grep -v '\#' versions.txt | grep newrelic-instrumentation-nodejs | awk -F= '{print "NEWRELIC_INSTRUMENTATION_NODEJS_VERSION="$2}' >> $GITHUB_ENV
2525
grep -v '\#' versions.txt | grep newrelic-instrumentation-python | awk -F= '{print "NEWRELIC_INSTRUMENTATION_PYTHON_VERSION="$2}' >> $GITHUB_ENV
2626
grep -v '\#' versions.txt | grep newrelic-instrumentation-dotnet | awk -F= '{print "NEWRELIC_INSTRUMENTATION_DOTNET_VERSION="$2}' >> $GITHUB_ENV
27+
grep -v '\#' versions.txt | grep newrelic-instrumentation-php | awk -F= '{print "NEWRELIC_INSTRUMENTATION_PHP_VERSION="$2}' >> $GITHUB_ENV
2728
echo "VERSION_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_ENV
2829
echo "VERSION=$(git describe --tags | sed 's/^v//')" >> $GITHUB_ENV
2930
@@ -76,5 +77,6 @@ jobs:
7677
NEWRELIC_INSTRUMENTATION_NODEJS_VERSION=${{ env.NEWRELIC_INSTRUMENTATION_NODEJS_VERSION }}
7778
NEWRELIC_INSTRUMENTATION_PYTHON_VERSION=${{ env.NEWRELIC_INSTRUMENTATION_PYTHON_VERSION }}
7879
NEWRELIC_INSTRUMENTATION_DOTNET_VERSION=${{ env.NEWRELIC_INSTRUMENTATION_DOTNET_VERSION }}
80+
NEWRELIC_INSTRUMENTATION_PHP_VERSION=${{ env.NEWRELIC_INSTRUMENTATION_PHP_VERSION }}
7981
cache-from: type=local,src=/tmp/.buildx-cache
8082
cache-to: type=local,dest=/tmp/.buildx-cache
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
name: "Publish php Newrelic-Instrumentation"
2+
3+
on:
4+
push:
5+
paths:
6+
- 'autoinstrumentation/php/**'
7+
- '.github/workflows/publish-newrelic-instrumentation-php.yaml'
8+
branches:
9+
- main
10+
pull_request:
11+
paths:
12+
- 'autoinstrumentation/php/**'
13+
- '.github/workflows/publish-newrelic-instrumentation-php.yaml'
14+
workflow_dispatch:
15+
16+
jobs:
17+
publish:
18+
runs-on: ubuntu-20.04
19+
20+
steps:
21+
- uses: actions/checkout@v3
22+
23+
- name: Read version
24+
run: echo "VERSION=$(cat autoinstrumentation/php/version.txt)" >> $GITHUB_ENV
25+
26+
- name: Docker meta
27+
id: meta
28+
uses: docker/metadata-action@v4
29+
with:
30+
images: ghcr.io/${{ github.repository_owner }}/newrelic-agent-operator/instrumentation-php
31+
tags: |
32+
type=match,pattern=v(.*),group=1,value=v${{ env.VERSION }}
33+
34+
- name: Set up QEMU
35+
uses: docker/setup-qemu-action@v2
36+
37+
- name: Set up Docker Buildx
38+
uses: docker/setup-buildx-action@v2
39+
40+
- name: Cache Docker layers
41+
uses: actions/cache@v3
42+
with:
43+
path: /tmp/.buildx-cache
44+
key: ${{ runner.os }}-buildx-${{ github.sha }}
45+
restore-keys: |
46+
${{ runner.os }}-buildx-
47+
48+
- name: Login to GitHub Package Registry
49+
uses: docker/login-action@v2
50+
with:
51+
registry: ghcr.io
52+
username: ${{ github.repository_owner }}
53+
password: ${{ secrets.GITHUB_TOKEN }}
54+
55+
- name: Build and push
56+
uses: docker/build-push-action@v4
57+
with:
58+
context: autoinstrumentation/php
59+
platforms: linux/amd64,linux/arm64
60+
push: true
61+
build-args: version=${{ env.VERSION }}
62+
tags: ${{ steps.meta.outputs.tags }}
63+
labels: ${{ steps.meta.outputs.labels }}
64+
cache-from: type=local,src=/tmp/.buildx-cache
65+
cache-to: type=local,dest=/tmp/.buildx-cache

Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,14 @@ ARG NEWRELIC_INSTRUMENTATION_JAVA_VERSION
2525
ARG NEWRELIC_INSTRUMENTATION_NODEJS_VERSION
2626
ARG NEWRELIC_INSTRUMENTATION_PYTHON_VERSION
2727
ARG NEWRELIC_INSTRUMENTATION_DOTNET_VERSION
28+
ARG NEWRELIC_INSTRUMENTATION_PHP_VERSION
2829
ARG AUTO_INSTRUMENTATION_GO_VERSION
2930
# Build
3031
# the GOARCH has not a default value to allow the binary be built according to the host where the command
3132
# was called. For example, if we call make docker-build in a local env which has the Apple Silicon M1 SO
3233
# the docker BUILDPLATFORM arg will be linux/arm64 when for Apple x86 it will be linux/amd64. Therefore,
3334
# by leaving it empty we can ensure that the container and binary shipped on it will have the same platform.
34-
RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -ldflags="-X ${VERSION_PKG}.version=${VERSION} -X ${VERSION_PKG}.buildDate=${VERSION_DATE} -X ${VERSION_PKG}.autoInstrumentationJava=${NEWRELIC_INSTRUMENTATION_JAVA_VERSION} -X ${VERSION_PKG}.autoInstrumentationNodeJS=${NEWRELIC_INSTRUMENTATION_NODEJS_VERSION} -X ${VERSION_PKG}.autoInstrumentationPython=${NEWRELIC_INSTRUMENTATION_PYTHON_VERSION} -X ${VERSION_PKG}.autoInstrumentationDotNet=${NEWRELIC_INSTRUMENTATION_DOTNET_VERSION}" -a -o manager cmd/main.go
35+
RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -ldflags="-X ${VERSION_PKG}.version=${VERSION} -X ${VERSION_PKG}.buildDate=${VERSION_DATE} -X ${VERSION_PKG}.autoInstrumentationJava=${NEWRELIC_INSTRUMENTATION_JAVA_VERSION} -X ${VERSION_PKG}.autoInstrumentationNodeJS=${NEWRELIC_INSTRUMENTATION_NODEJS_VERSION} -X ${VERSION_PKG}.autoInstrumentationPython=${NEWRELIC_INSTRUMENTATION_PYTHON_VERSION} -X ${VERSION_PKG}.autoInstrumentationDotNet=${NEWRELIC_INSTRUMENTATION_DOTNET_VERSION} -X ${VERSION_PKG}.autoInstrumentationPhp=${NEWRELIC_INSTRUMENTATION_PHP_VERSION}" -a -o manager cmd/main.go
3536

3637
# Use distroless as minimal base image to package the manager binary
3738
# Refer to https://github.com/GoogleContainerTools/distroless for more details

Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ NEWRELIC_INSTRUMENTATION_JAVA_VERSION ?= "$(shell grep -v '\#' versions.txt | gr
1111
NEWRELIC_INSTRUMENTATION_NODEJS_VERSION ?= "$(shell grep -v '\#' versions.txt | grep newrelic-instrumentation-nodejs | awk -F= '{print $$2}')"
1212
NEWRELIC_INSTRUMENTATION_PYTHON_VERSION ?= "$(shell grep -v '\#' versions.txt | grep newrelic-instrumentation-python | awk -F= '{print $$2}')"
1313
NEWRELIC_INSTRUMENTATION_DOTNET_VERSION ?= "$(shell grep -v '\#' versions.txt | grep newrelic-instrumentation-dotnet | awk -F= '{print $$2}')"
14+
NEWRELIC_INSTRUMENTATION_PHP_VERSION ?= "$(shell grep -v '\#' versions.txt | grep newrelic-instrumentation-php | awk -F= '{print $$2}')"
1415
AUTO_INSTRUMENTATION_GO_VERSION ?= "$(shell grep -v '\#' versions.txt | grep autoinstrumentation-go | awk -F= '{print $$2}')"
15-
LD_FLAGS ?= "-X ${VERSION_PKG}.version=${VERSION} -X ${VERSION_PKG}.buildDate=${VERSION_DATE} -X ${VERSION_PKG}.autoInstrumentationJava=${NEWRELIC_INSTRUMENTATION_JAVA_VERSION} -X ${VERSION_PKG}.autoInstrumentationNodeJS=${NEWRELIC_INSTRUMENTATION_NODEJS_VERSION} -X ${VERSION_PKG}.autoInstrumentationPython=${NEWRELIC_INSTRUMENTATION_PYTHON_VERSION} -X ${VERSION_PKG}.autoInstrumentationGo=${AUTO_INSTRUMENTATION_GO_VERSION} -X ${VERSION_PKG}.autoInstrumentationDotNet=${NEWRELIC_INSTRUMENTATION_DOTNET_VERSION}"
16+
LD_FLAGS ?= "-X ${VERSION_PKG}.version=${VERSION} -X ${VERSION_PKG}.buildDate=${VERSION_DATE} -X ${VERSION_PKG}.autoInstrumentationJava=${NEWRELIC_INSTRUMENTATION_JAVA_VERSION} -X ${VERSION_PKG}.autoInstrumentationNodeJS=${NEWRELIC_INSTRUMENTATION_NODEJS_VERSION} -X ${VERSION_PKG}.autoInstrumentationPython=${NEWRELIC_INSTRUMENTATION_PYTHON_VERSION} -X ${VERSION_PKG}.autoInstrumentationGo=${AUTO_INSTRUMENTATION_GO_VERSION} -X ${VERSION_PKG}.autoInstrumentationDotNet=${NEWRELIC_INSTRUMENTATION_DOTNET_VERSION} -X ${VERSION_PKG}.autoInstrumentationPhp=${NEWRELIC_INSTRUMENTATION_PHP_VERSION}"
1617
ARCH ?= $(shell go env GOARCH)
1718

1819
# Image URL to use all building/pushing image targets
@@ -155,7 +156,7 @@ scorecard-tests: operator-sdk
155156
# buildx is used to ensure same results for arm based systems (m1/2 chips)
156157
.PHONY: container
157158
container:
158-
docker buildx build --load --platform linux/${ARCH} -t ${IMG} --build-arg VERSION_PKG=${VERSION_PKG} --build-arg VERSION=${VERSION} --build-arg VERSION_DATE=${VERSION_DATE} --build-arg NEWRELIC_INSTRUMENTATION_JAVA_VERSION=${NEWRELIC_INSTRUMENTATION_JAVA_VERSION} --build-arg NEWRELIC_INSTRUMENTATION_NODEJS_VERSION=${NEWRELIC_INSTRUMENTATION_NODEJS_VERSION} --build-arg NEWRELIC_INSTRUMENTATION_PYTHON_VERSION=${NEWRELIC_INSTRUMENTATION_PYTHON_VERSION} --build-arg NEWRELIC_INSTRUMENTATION_DOTNET_VERSION=${NEWRELIC_INSTRUMENTATION_DOTNET_VERSION} .
159+
docker buildx build --load --platform linux/${ARCH} -t ${IMG} --build-arg VERSION_PKG=${VERSION_PKG} --build-arg VERSION=${VERSION} --build-arg VERSION_DATE=${VERSION_DATE} --build-arg NEWRELIC_INSTRUMENTATION_JAVA_VERSION=${NEWRELIC_INSTRUMENTATION_JAVA_VERSION} --build-arg NEWRELIC_INSTRUMENTATION_NODEJS_VERSION=${NEWRELIC_INSTRUMENTATION_NODEJS_VERSION} --build-arg NEWRELIC_INSTRUMENTATION_PYTHON_VERSION=${NEWRELIC_INSTRUMENTATION_PYTHON_VERSION} --build-arg NEWRELIC_INSTRUMENTATION_DOTNET_VERSION=${NEWRELIC_INSTRUMENTATION_DOTNET_VERSION} --build-arg NEWRELIC_INSTRUMENTATION_PHP_VERSION=${NEWRELIC_INSTRUMENTATION_PHP_VERSION} .
159160

160161
# Push the container image, used only for local dev purposes
161162
.PHONY: container-push

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ spec:
6363
image: ghcr.io/newrelic-experimental/newrelic-agent-operator/instrumentation-python:latest
6464
dotnet:
6565
image: ghcr.io/newrelic-experimental/newrelic-agent-operator/instrumentation-dotnet:latest
66+
php:
67+
image: ghcr.io/newrelic-experimental/newrelic-agent-operator/instrumentation-php:latest
6668
go:
6769
image: ghcr.io/open-telemetry/opentelemetry-go-instrumentation/autoinstrumentation-go:latest
6870
```

api/v1alpha1/groupversion_info.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2023.
2+
Copyright 2024.
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.

api/v1alpha1/instrumentation_types.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2023.
2+
Copyright 2024.
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.
@@ -67,6 +67,10 @@ type InstrumentationSpec struct {
6767
// +optional
6868
DotNet DotNet `json:"dotnet,omitempty"`
6969

70+
// Php defines configuration for DotNet auto-instrumentation.
71+
// +optional
72+
Php Php `json:"php,omitempty"`
73+
7074
// Go defines configuration for Go auto-instrumentation.
7175
// When using Go auto-instrumentation you must provide a value for the OTEL_GO_AUTO_TARGET_EXE env var via the
7276
// Instrumentation env vars or via the instrumentation.opentelemetry.io/otel-go-auto-target-exe pod annotation.
@@ -156,6 +160,17 @@ type DotNet struct {
156160
Env []corev1.EnvVar `json:"env,omitempty"`
157161
}
158162

163+
type Php struct {
164+
// Image is a container image with DotNet agent and auto-instrumentation.
165+
// +optional
166+
Image string `json:"image,omitempty"`
167+
168+
// Env defines DotNet specific env vars.
169+
// If the former var had been defined, then the other vars would be ignored.
170+
// +optional
171+
Env []corev1.EnvVar `json:"env,omitempty"`
172+
}
173+
159174
type Go struct {
160175
// Image is a container image with Go SDK and auto-instrumentation.
161176
// +optional

api/v1alpha1/instrumentation_webhook.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2023.
2+
Copyright 2024.
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.
@@ -32,6 +32,7 @@ const (
3232
AnnotationDefaultAutoInstrumentationNodeJS = "instrumentation.newrelic.com/default-auto-instrumentation-nodejs-image"
3333
AnnotationDefaultAutoInstrumentationPython = "instrumentation.newrelic.com/default-auto-instrumentation-python-image"
3434
AnnotationDefaultAutoInstrumentationDotNet = "instrumentation.newrelic.com/default-auto-instrumentation-dotnet-image"
35+
AnnotationDefaultAutoInstrumentationPhp = "instrumentation.newrelic.com/default-auto-instrumentation-php-image"
3536
AnnotationDefaultAutoInstrumentationGo = "instrumentation.newrelic.com/default-auto-instrumentation-go-image"
3637
envNewRelicPrefix = "NEW_RELIC_"
3738
envOtelPrefix = "OTEL_"
@@ -80,6 +81,11 @@ func (r *Instrumentation) Default() {
8081
r.Spec.DotNet.Image = val
8182
}
8283
}
84+
if r.Spec.Php.Image == "" {
85+
if val, ok := r.Annotations[AnnotationDefaultAutoInstrumentationPhp]; ok {
86+
r.Spec.DotNet.Image = val
87+
}
88+
}
8389
if r.Spec.Go.Image == "" {
8490
if val, ok := r.Annotations[AnnotationDefaultAutoInstrumentationGo]; ok {
8591
r.Spec.Go.Image = val
@@ -128,6 +134,9 @@ func (r *Instrumentation) validate() error {
128134
if err := r.validateEnv(r.Spec.DotNet.Env); err != nil {
129135
return err
130136
}
137+
if err := r.validateEnv(r.Spec.Php.Env); err != nil {
138+
return err
139+
}
131140
if err := r.validateEnv(r.Spec.Go.Env); err != nil {
132141
return err
133142
}

api/v1alpha1/upgrade_strategy.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2023.
2+
Copyright 2024.
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.

api/v1alpha1/webhook_suite_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2023.
2+
Copyright 2024.
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.

0 commit comments

Comments
 (0)