Skip to content

Commit

Permalink
feat: instrumentation rule for otel distros (#2396)
Browse files Browse the repository at this point in the history
This is to move away from the Deprecated `OtelSdk` and towards using the
more generic OtelDistribution

---------

Co-authored-by: Ron Federman <[email protected]>
  • Loading branch information
blumamir and RonFed authored Feb 6, 2025
1 parent 29b06d7 commit fbfa791
Show file tree
Hide file tree
Showing 11 changed files with 116 additions and 17 deletions.
20 changes: 16 additions & 4 deletions api/config/crd/bases/odigos.io_instrumentationrules.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,23 @@ spec:
regarding the rule for convenience. For example: why it was added.
Odigos does not use or assume any meaning from this field.'
type: string
otelDistros:
description: Set the otel distros to use instead of the defaults.
properties:
otelDistroNames:
description: |-
Set a list of distribution names that take priority over the default distributions.
if a language is not in this list, the default distribution will be used.
it multiple distributions are specified for the same language, in one or many rules,
the behavior is undefined.
items:
type: string
type: array
required:
- otelDistroNames
type: object
otelSdks:
description: |-
Set the OtelSdk to use for the workloads in this rule.
instrumentation libraries will be ignored if set.
the rule will be used only for languages which are specified, and ignored otherwise.
description: 'Deprecated: use OrelDistros instead.'
properties:
otelSdkByLanguage:
additionalProperties:
Expand Down

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

7 changes: 4 additions & 3 deletions api/odigos/v1alpha1/instrumentationrule_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,12 @@ type InstrumentationRuleSpec struct {
// Allows to configure payload collection aspects for different types of payloads.
PayloadCollection *instrumentationrules.PayloadCollection `json:"payloadCollection,omitempty"`

// Set the OtelSdk to use for the workloads in this rule.
// instrumentation libraries will be ignored if set.
// the rule will be used only for languages which are specified, and ignored otherwise.
// Deprecated: use OrelDistros instead.
OtelSdks *instrumentationrules.OtelSdks `json:"otelSdks,omitempty"`

// Set the otel distros to use instead of the defaults.
OtelDistros *instrumentationrules.OtelDistros `json:"otelDistros,omitempty"`

// Configure which code attributes should be recorded as span attributes.
CodeAttributes *instrumentationrules.CodeAttributes `json:"codeAttributes,omitempty"`
}
Expand Down
12 changes: 12 additions & 0 deletions api/odigos/v1alpha1/instrumentationrules/otel-sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@ import "github.com/odigos-io/odigos/common"

// +kubebuilder:object:generate=true
// +kubebuilder:deepcopy-gen=true
// Deprecated: Use OtelDistro instead
type OtelSdks struct {
OtelSdkByLanguage map[common.ProgrammingLanguage]common.OtelSdk `json:"otelSdkByLanguage"`
}

// +kubebuilder:object:generate=true
// +kubebuilder:deepcopy-gen=true
type OtelDistros struct {

// Set a list of distribution names that take priority over the default distributions.
// if a language is not in this list, the default distribution will be used.
// it multiple distributions are specified for the same language, in one or many rules,
// the behavior is undefined.
OtelDistroNames []string `json:"otelDistroNames"`
}
20 changes: 20 additions & 0 deletions api/odigos/v1alpha1/instrumentationrules/zz_generated.deepcopy.go

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

5 changes: 5 additions & 0 deletions api/odigos/v1alpha1/zz_generated.deepcopy.go

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

15 changes: 12 additions & 3 deletions docs/api-reference/odigos.io.v1alpha1.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -1869,9 +1869,18 @@ If empty, no instrumentation libraries will be used.</p>
<a href="https://pkg.go.dev/github.com/odigos-io/odigos/api/odigos/v1alpha1/instrumentationrules#OtelSdks"><code>instrumentationrules.OtelSdks</code></a>
</td>
<td>
<p>Set the OtelSdk to use for the workloads in this rule.
instrumentation libraries will be ignored if set.
the rule will be used only for languages which are specified, and ignored otherwise.</p>
<p>Deprecated: use OrelDistros instead.</p>
</td>
</tr>
<tr>
<td>
<code>otelDistros</code> <B>[Required]</B>
</td>
<td>
<a href="https://pkg.go.dev/github.com/odigos-io/odigos/api/odigos/v1alpha1/instrumentationrules#OtelDistros"><code>instrumentationrules.OtelDistros</code></a>
</td>
<td>
<p>Set the otel distros to use instead of the defaults.</p>
</td>
</tr>
<tr>
Expand Down
20 changes: 16 additions & 4 deletions helm/odigos/templates/crds/odigos.io_instrumentationrules.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,23 @@ spec:
regarding the rule for convenience. For example: why it was added.
Odigos does not use or assume any meaning from this field.'
type: string
otelDistros:
description: Set the otel distros to use instead of the defaults.
properties:
otelDistroNames:
description: |-
Set a list of distribution names that take priority over the default distributions.
if a language is not in this list, the default distribution will be used.
it multiple distributions are specified for the same language, in one or many rules,
the behavior is undefined.
items:
type: string
type: array
required:
- otelDistroNames
type: object
otelSdks:
description: |-
Set the OtelSdk to use for the workloads in this rule.
instrumentation libraries will be ignored if set.
the rule will be used only for languages which are specified, and ignored otherwise.
description: 'Deprecated: use OrelDistros instead.'
properties:
otelSdkByLanguage:
additionalProperties:
Expand Down
19 changes: 16 additions & 3 deletions instrumentor/controllers/agentenabled/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,14 +344,27 @@ func containerInstrumentationConfig(containerName string,
func applyRulesForDistros(defaultDistros map[common.ProgrammingLanguage]string,
instrumentationRules *[]odigosv1.InstrumentationRule) map[common.ProgrammingLanguage]string {

distrosPerLanguage := make(map[common.ProgrammingLanguage]string, len(defaultDistros))
for lang, distroName := range defaultDistros {
distrosPerLanguage[lang] = distroName
}

for _, rule := range *instrumentationRules {
if rule.Spec.OtelSdks == nil {
if rule.Spec.OtelDistros == nil {
continue
}
// TODO: change this from otel sdks to distros and use distro name
for _, distroName := range rule.Spec.OtelDistros.OtelDistroNames {
distro := distros.GetDistroByName(distroName)
if distro == nil {
continue
}

lang := distro.Language
distrosPerLanguage[lang] = distroName
}
}

return defaultDistros
return distrosPerLanguage
}

// This function checks if we are waiting for some transient prerequisites to be completed before injecting the agent.
Expand Down
3 changes: 3 additions & 0 deletions profiles/manifests/java-ebpf-instrumentations.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ spec:
java:
sdkTier: "enterprise"
sdkType: "ebpf"
otelDistros:
otelDistroNames:
- "java-ebpf-instrumentations"
3 changes: 3 additions & 0 deletions profiles/manifests/legacy-dotnet-instrumentation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ spec:
dotnet:
sdkTier: "enterprise"
sdkType: "native"
otelDistros:
otelDistroNames:
- "dotnet-legacy"

0 comments on commit fbfa791

Please sign in to comment.