Skip to content
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

feat(nodejs-autoinstrumentation): enable overriding default histogram buckets #3448

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .chloggen/3436-nodejs-autosintrumentation-buckets.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: enhancement

# The name of the component, or a single word describing the area of concern, (e.g. collector, target allocator, auto-instrumentation, opamp, github action)
component: auto-instrumentation

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Support overriding the default histogram bucket list via the `spec.nodejs.histogramBuckets` field on the Instrumentation Custom Resource.

# One or more tracking issues related to the change
issues: [3436]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:
9 changes: 9 additions & 0 deletions apis/v1alpha1/instrumentation_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,15 @@
// Resources describes the compute resource requirements.
// +optional
Resources corev1.ResourceRequirements `json:"resourceRequirements,omitempty"`

// HistogramBuckets defines the histogram buckets for metrics generated by the NodeJS SDK.
// +optional
HistogramBuckets []HistogramBucketsItem `json:"histogramBuckets,omitempty"`
}

type HistogramBucketsItem struct {
Name string `json:"instrumentName"`
Buckets []float64 `json:"buckets"`

Check failure on line 228 in apis/v1alpha1/instrumentation_types.go

View workflow job for this annotation

GitHub Actions / e2e-tests (1.23, e2e-pdb)

found float, the usage of which is highly discouraged, as support for them varies across languages. Please consider serializing your float as string instead. If you are really sure you want to use them, re-run with crd:allowDangerousTypes=true

Check failure on line 228 in apis/v1alpha1/instrumentation_types.go

View workflow job for this annotation

GitHub Actions / e2e-tests (1.23, e2e-multi-instrumentation)

found float, the usage of which is highly discouraged, as support for them varies across languages. Please consider serializing your float as string instead. If you are really sure you want to use them, re-run with crd:allowDangerousTypes=true

Check failure on line 228 in apis/v1alpha1/instrumentation_types.go

View workflow job for this annotation

GitHub Actions / e2e-tests (1.23, e2e-opampbridge)

found float, the usage of which is highly discouraged, as support for them varies across languages. Please consider serializing your float as string instead. If you are really sure you want to use them, re-run with crd:allowDangerousTypes=true

Check failure on line 228 in apis/v1alpha1/instrumentation_types.go

View workflow job for this annotation

GitHub Actions / e2e-tests (1.23, e2e-automatic-rbac)

found float, the usage of which is highly discouraged, as support for them varies across languages. Please consider serializing your float as string instead. If you are really sure you want to use them, re-run with crd:allowDangerousTypes=true

Check failure on line 228 in apis/v1alpha1/instrumentation_types.go

View workflow job for this annotation

GitHub Actions / e2e-tests (1.23, e2e-targetallocator-cr)

found float, the usage of which is highly discouraged, as support for them varies across languages. Please consider serializing your float as string instead. If you are really sure you want to use them, re-run with crd:allowDangerousTypes=true

Check failure on line 228 in apis/v1alpha1/instrumentation_types.go

View workflow job for this annotation

GitHub Actions / e2e-tests (1.31, e2e-targetallocator)

found float, the usage of which is highly discouraged, as support for them varies across languages. Please consider serializing your float as string instead. If you are really sure you want to use them, re-run with crd:allowDangerousTypes=true

Check failure on line 228 in apis/v1alpha1/instrumentation_types.go

View workflow job for this annotation

GitHub Actions / e2e-tests (e2e-native-sidecar, 1.29, add-operator-arg OPERATOR_ARG='--feature-gates=operator.side...

found float, the usage of which is highly discouraged, as support for them varies across languages. Please consider serializing your float as string instead. If you are really sure you want to use them, re-run with crd:allowDangerousTypes=true

Check failure on line 228 in apis/v1alpha1/instrumentation_types.go

View workflow job for this annotation

GitHub Actions / e2e-tests (1.31, e2e-targetallocator-cr)

found float, the usage of which is highly discouraged, as support for them varies across languages. Please consider serializing your float as string instead. If you are really sure you want to use them, re-run with crd:allowDangerousTypes=true

Check failure on line 228 in apis/v1alpha1/instrumentation_types.go

View workflow job for this annotation

GitHub Actions / e2e-tests (1.31, e2e-metadata-filters)

found float, the usage of which is highly discouraged, as support for them varies across languages. Please consider serializing your float as string instead. If you are really sure you want to use them, re-run with crd:allowDangerousTypes=true

Check failure on line 228 in apis/v1alpha1/instrumentation_types.go

View workflow job for this annotation

GitHub Actions / e2e-tests (1.31, e2e-prometheuscr)

found float, the usage of which is highly discouraged, as support for them varies across languages. Please consider serializing your float as string instead. If you are really sure you want to use them, re-run with crd:allowDangerousTypes=true

Check failure on line 228 in apis/v1alpha1/instrumentation_types.go

View workflow job for this annotation

GitHub Actions / e2e-tests (1.31, e2e-instrumentation)

found float, the usage of which is highly discouraged, as support for them varies across languages. Please consider serializing your float as string instead. If you are really sure you want to use them, re-run with crd:allowDangerousTypes=true

Check failure on line 228 in apis/v1alpha1/instrumentation_types.go

View workflow job for this annotation

GitHub Actions / e2e-tests (1.23, e2e-autoscale)

found float, the usage of which is highly discouraged, as support for them varies across languages. Please consider serializing your float as string instead. If you are really sure you want to use them, re-run with crd:allowDangerousTypes=true

Check failure on line 228 in apis/v1alpha1/instrumentation_types.go

View workflow job for this annotation

GitHub Actions / e2e-tests (1.31, e2e-upgrade)

found float, the usage of which is highly discouraged, as support for them varies across languages. Please consider serializing your float as string instead. If you are really sure you want to use them, re-run with crd:allowDangerousTypes=true

Check failure on line 228 in apis/v1alpha1/instrumentation_types.go

View workflow job for this annotation

GitHub Actions / e2e-tests (1.31, e2e-opampbridge)

found float, the usage of which is highly discouraged, as support for them varies across languages. Please consider serializing your float as string instead. If you are really sure you want to use them, re-run with crd:allowDangerousTypes=true

Check failure on line 228 in apis/v1alpha1/instrumentation_types.go

View workflow job for this annotation

GitHub Actions / e2e-tests (1.31, e2e-autoscale)

found float, the usage of which is highly discouraged, as support for them varies across languages. Please consider serializing your float as string instead. If you are really sure you want to use them, re-run with crd:allowDangerousTypes=true

Check failure on line 228 in apis/v1alpha1/instrumentation_types.go

View workflow job for this annotation

GitHub Actions / e2e-tests (1.23, e2e-upgrade)

found float, the usage of which is highly discouraged, as support for them varies across languages. Please consider serializing your float as string instead. If you are really sure you want to use them, re-run with crd:allowDangerousTypes=true

Check failure on line 228 in apis/v1alpha1/instrumentation_types.go

View workflow job for this annotation

GitHub Actions / e2e-tests (1.23, e2e-prometheuscr)

found float, the usage of which is highly discouraged, as support for them varies across languages. Please consider serializing your float as string instead. If you are really sure you want to use them, re-run with crd:allowDangerousTypes=true

Check failure on line 228 in apis/v1alpha1/instrumentation_types.go

View workflow job for this annotation

GitHub Actions / e2e-tests (1.31, e2e-automatic-rbac)

found float, the usage of which is highly discouraged, as support for them varies across languages. Please consider serializing your float as string instead. If you are really sure you want to use them, re-run with crd:allowDangerousTypes=true

Check failure on line 228 in apis/v1alpha1/instrumentation_types.go

View workflow job for this annotation

GitHub Actions / e2e-tests (1.23, e2e-metadata-filters)

found float, the usage of which is highly discouraged, as support for them varies across languages. Please consider serializing your float as string instead. If you are really sure you want to use them, re-run with crd:allowDangerousTypes=true

Check failure on line 228 in apis/v1alpha1/instrumentation_types.go

View workflow job for this annotation

GitHub Actions / e2e-tests (1.31, e2e-multi-instrumentation)

found float, the usage of which is highly discouraged, as support for them varies across languages. Please consider serializing your float as string instead. If you are really sure you want to use them, re-run with crd:allowDangerousTypes=true

Check failure on line 228 in apis/v1alpha1/instrumentation_types.go

View workflow job for this annotation

GitHub Actions / e2e-tests (1.23, e2e)

found float, the usage of which is highly discouraged, as support for them varies across languages. Please consider serializing your float as string instead. If you are really sure you want to use them, re-run with crd:allowDangerousTypes=true

Check failure on line 228 in apis/v1alpha1/instrumentation_types.go

View workflow job for this annotation

GitHub Actions / e2e-tests (1.31, e2e)

found float, the usage of which is highly discouraged, as support for them varies across languages. Please consider serializing your float as string instead. If you are really sure you want to use them, re-run with crd:allowDangerousTypes=true

Check failure on line 228 in apis/v1alpha1/instrumentation_types.go

View workflow job for this annotation

GitHub Actions / e2e-tests (1.31, e2e-pdb)

found float, the usage of which is highly discouraged, as support for them varies across languages. Please consider serializing your float as string instead. If you are really sure you want to use them, re-run with crd:allowDangerousTypes=true

Check failure on line 228 in apis/v1alpha1/instrumentation_types.go

View workflow job for this annotation

GitHub Actions / e2e-tests (1.23, e2e-targetallocator)

found float, the usage of which is highly discouraged, as support for them varies across languages. Please consider serializing your float as string instead. If you are really sure you want to use them, re-run with crd:allowDangerousTypes=true

Check failure on line 228 in apis/v1alpha1/instrumentation_types.go

View workflow job for this annotation

GitHub Actions / e2e-tests (1.31, e2e-ta-collector-mtls)

found float, the usage of which is highly discouraged, as support for them varies across languages. Please consider serializing your float as string instead. If you are really sure you want to use them, re-run with crd:allowDangerousTypes=true

Check failure on line 228 in apis/v1alpha1/instrumentation_types.go

View workflow job for this annotation

GitHub Actions / e2e-tests (1.23, e2e-ta-collector-mtls)

found float, the usage of which is highly discouraged, as support for them varies across languages. Please consider serializing your float as string instead. If you are really sure you want to use them, re-run with crd:allowDangerousTypes=true

Check failure on line 228 in apis/v1alpha1/instrumentation_types.go

View workflow job for this annotation

GitHub Actions / e2e-tests (1.23, e2e-instrumentation)

found float, the usage of which is highly discouraged, as support for them varies across languages. Please consider serializing your float as string instead. If you are really sure you want to use them, re-run with crd:allowDangerousTypes=true

Check failure on line 228 in apis/v1alpha1/instrumentation_types.go

View workflow job for this annotation

GitHub Actions / Unit tests

found float, the usage of which is highly discouraged, as support for them varies across languages. Please consider serializing your float as string instead. If you are really sure you want to use them, re-run with crd:allowDangerousTypes=true
}

// Python defines Python SDK and instrumentation configuration.
Expand Down
27 changes: 27 additions & 0 deletions apis/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 30 additions & 1 deletion autoinstrumentation/nodejs/src/autoinstrumentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { OTLPTraceExporter as OTLPHttpTraceExporter } from '@opentelemetry/expor
import { OTLPTraceExporter as OTLPGrpcTraceExporter } from '@opentelemetry/exporter-trace-otlp-grpc';
import { OTLPMetricExporter } from '@opentelemetry/exporter-metrics-otlp-grpc';
import { PrometheusExporter } from '@opentelemetry/exporter-prometheus';
import { PeriodicExportingMetricReader } from '@opentelemetry/sdk-metrics';
import { ExplicitBucketHistogramAggregation, PeriodicExportingMetricReader, View } from "@opentelemetry/sdk-metrics";
import { alibabaCloudEcsDetector } from '@opentelemetry/resource-detector-alibaba-cloud';
import { awsEc2Detector, awsEksDetector } from '@opentelemetry/resource-detector-aws';
import { containerDetector } from '@opentelemetry/resource-detector-container';
Expand Down Expand Up @@ -50,11 +50,39 @@ function getMetricReader() {
}
}

function getViews() {
const histogramBuckets = process.env.OTEL_OPERATOR_NODEJS_HISTOGRAM_BUCKETS;
if (histogramBuckets) {
try {
let views = [];
for (const viewCfg of JSON.parse(histogramBuckets)) {
views.push(
new View({
instrumentName: viewCfg["instrumentName"],
aggregation: new ExplicitBucketHistogramAggregation(
viewCfg["buckets"],
),
}),
);
}
return views;
} catch (error) {
diag.error(
"Failed to parse OTEL_OPERATOR_NODEJS_HISTOGRAM_BUCKETS:",
error,
);
}
return [];
}
return [];
}

const sdk = new NodeSDK({
autoDetectResources: true,
instrumentations: [getNodeAutoInstrumentations()],
traceExporter: getTraceExporter(),
metricReader: getMetricReader(),
views: getViews(),
resourceDetectors:
[
// Standard resource detectors.
Expand All @@ -75,3 +103,4 @@ const sdk = new NodeSDK({
});

sdk.start();

11 changes: 11 additions & 0 deletions config/crd/bases/opentelemetry.io_instrumentations.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1393,6 +1393,17 @@ spec:
type: object
nodejs:
properties:
histogramBuckets:
type: array
items:
type: object
properties:
instrumentName:
type: string
buckets:
type: array
items:
type: number
env:
items:
properties:
Expand Down
18 changes: 17 additions & 1 deletion pkg/instrumentation/nodejs.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ package instrumentation

import (
corev1 "k8s.io/api/core/v1"

"encoding/json"
"github.com/open-telemetry/opentelemetry-operator/apis/v1alpha1"
)

Expand All @@ -26,9 +26,25 @@ const (
nodejsInitContainerName = initContainerName + "-nodejs"
nodejsVolumeName = volumeName + "-nodejs"
nodejsInstrMountPath = "/otel-auto-instrumentation-nodejs"
histogramBucketsEnvVarName = "OTEL_OPERATOR_NODEJS_HISTOGRAM_BUCKETS"
)

func injectNodeJSSDK(nodeJSSpec v1alpha1.NodeJS, pod corev1.Pod, index int) (corev1.Pod, error) {
if len(nodeJSSpec.HistogramBuckets) > 0 {
bucketsJSON, err := json.Marshal(nodeJSSpec.HistogramBuckets)
if err != nil {
// handle error, possibly log and skip injection for this resource
return pod, err
}

// Inject as an environment variable in the pod
bucketsJSONEnvVar := corev1.EnvVar{
Name: histogramBucketsEnvVarName,
Value: string(bucketsJSON),
}
nodeJSSpec.Env = append(nodeJSSpec.Env, bucketsJSONEnvVar)
}

volume := instrVolume(nodeJSSpec.VolumeClaimTemplate, nodejsVolumeName, nodeJSSpec.VolumeSizeLimit)

// caller checks if there is at least one container.
Expand Down
Loading