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

Minimal java inspection improvement #2478

Open
wants to merge 15 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
72 changes: 40 additions & 32 deletions odiglet/debug.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
FROM python:3.11 AS python-builder
######### python Native Community Agent #########

FROM python:3.11.9 AS python-builder
ARG ODIGOS_VERSION
WORKDIR /python-instrumentation
COPY ../agents/python ./agents/python
RUN echo "VERSION = \"$ODIGOS_VERSION\";" > ./agents/python/configurator/version.py
RUN mkdir workspace && pip install ./agents/python/ --target workspace

COPY agents/python ./agents/configurator
RUN pip install ./agents/configurator/ --target workspace
RUN echo "VERSION = \"$ODIGOS_VERSION\";" > /python-instrumentation/workspace/initializer/version.py

######### Node.js Native Community Agent #########
#
Expand All @@ -13,44 +14,53 @@ RUN mkdir workspace && pip install ./agents/python/ --target workspace
# The implemntation is based on the following blog post:
# https://www.docker.com/blog/dockerfiles-now-support-multiple-build-contexts/

# The first build stage 'nodejs-agent-native-community-clone' clones the agent sources from github main branch.
FROM alpine AS nodejs-agent-native-community-clone
# The first build stage 'nodejs-agent-clone' clones the agent sources from github main branch.
FROM alpine AS nodejs-agent-clone
RUN apk add git
WORKDIR /src
ARG NODEJS_AGENT_VERSION=main
RUN git clone https://github.com/odigos-io/opentelemetry-node.git && cd opentelemetry-node && git checkout $NODEJS_AGENT_VERSION

# The second build stage 'nodejs-agent-native-community-src' prepares the actual code we are going to compile and embed in odiglet.
# By default, it uses the previous 'nodejs-agent-native-community-src' stage, but one can override it by setting the
# --build-context nodejs-agent-native-community-src=../opentelemetry-node flag in the docker build command.
# The second build stage 'nodejs-agent-src' prepares the actual code we are going to compile and embed in odiglet.
# By default, it uses the previous 'nodejs-agent-src' stage, but one can override it by setting the
# --build-context nodejs-agent-src=../opentelemetry-node flag in the docker build command.
# This allows us to nobe the agent sources and test changes during development.
# The output of this stage is the resolved source code to be used in the next stage.
FROM scratch AS nodejs-agent-native-community-src
COPY --from=nodejs-agent-native-community-clone /src/opentelemetry-node /
FROM scratch AS nodejs-agent-src
COPY --from=nodejs-agent-clone /src/opentelemetry-node /

# The third step 'nodejs-agent-build' compiles the agent sources and prepares it for
# being dependency of the native-community agent.
FROM node:18 AS nodejs-agent-build
ARG ODIGOS_VERSION
WORKDIR /opentelemetry-node
COPY --from=nodejs-agent-src package.json yarn.lock ./
# install dependencies with dev so we can build the agent
RUN yarn --frozen-lockfile
COPY --from=nodejs-agent-src / .
RUN echo "export const VERSION = \"$ODIGOS_VERSION\";" > ./src/version.ts
RUN yarn compile

# The third build stage 'nodejs-agent-native-community-builder' compiles the agent sources and prepares the final output.
# it COPY from the previous 'nodejs-agent-native-community-src' stage, so it can be used with either the upstream or local sources.

# The fourth step 'nodejs-agent-native-community-src' prepares the agent sources for the native-community agent.
# it COPY the nodejs agent source from 'nodejs-agent-build' stage and then build the agent in the 'agents/nodejs-native-community' directory.
# The output of this stage is the compiled agent code in:
# - package source code in '/nodejs-instrumentation/build/src' directory.
# - all required dependencies in '/nodejs-instrumentation/prod_node_modules' directory.
# These artifacts are later copied into the odiglet final image to be mounted into auto-instrumented pods at runtime.
FROM node:18 AS nodejs-agent-native-community-builder
ARG ODIGOS_VERSION
WORKDIR /nodejs-instrumentation
COPY --from=nodejs-agent-native-community-src /package.json /yarn.lock ./
WORKDIR /repos
COPY ./agents/nodejs-native-community ./odigos/agents/nodejs-native-community
COPY --from=nodejs-agent-build /opentelemetry-node opentelemetry-node
# prepare the production node_modules content in a separate directory
RUN yarn --production --frozen-lockfile
RUN mv node_modules ./prod_node_modules
# install all dependencies including dev so we can yarn compile
RUN yarn --frozen-lockfile
COPY --from=nodejs-agent-native-community-src / ./
# inject the actual version into the agent code
RUN echo "export const VERSION = \"$ODIGOS_VERSION\";" > ./src/version.ts
RUN yarn compile
RUN yarn --cwd ./odigos/agents/nodejs-native-community --production --frozen-lockfile

FROM busybox:1.36.1 AS dotnet-builder


FROM --platform=$BUILDPLATFORM busybox:1.36.1 AS dotnet-builder
WORKDIR /dotnet-instrumentation
ARG DOTNET_OTEL_VERSION=v1.7.0
ARG DOTNET_OTEL_VERSION=v1.9.0
ARG TARGETARCH
RUN if [ "$TARGETARCH" = "arm64" ]; then \
echo "arm64" > /tmp/arch_suffix; \
Expand All @@ -76,7 +86,7 @@ RUN ARCH_SUFFIX=$(cat /tmp/arch_suffix) && \

FROM --platform=$BUILDPLATFORM registry.odigos.io/odiglet-base:v1.7 AS builder
WORKDIR /go/src/github.com/odigos-io/odigos
# Copyy local modules required by the build
# Copy local modules required by the build
COPY api/ api/
COPY common/ common/
COPY k8sutils/ k8sutils/
Expand All @@ -89,25 +99,23 @@ COPY odiglet/ .
ARG TARGETARCH
RUN --mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/go/pkg \
GOOS=linux GOARCH=$TARGETARCH make debug-build-odiglet
GOOS=linux GOARCH=$TARGETARCH make build-odiglet

# Install delve
RUN go install github.com/go-delve/delve/cmd/dlv@latest

WORKDIR /instrumentations

# Java
ARG JAVA_OTEL_VERSION=v2.6.0
ARG JAVA_OTEL_VERSION=v2.10.0
ADD https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/download/$JAVA_OTEL_VERSION/opentelemetry-javaagent.jar /instrumentations/java/javaagent.jar
RUN chmod 644 /instrumentations/java/javaagent.jar

# Python
COPY --from=python-builder /python-instrumentation/workspace /instrumentations/python

# NodeJS
COPY --from=nodejs-agent-native-community-builder /nodejs-instrumentation/build/src /instrumentations/nodejs
COPY --from=nodejs-agent-native-community-builder /nodejs-instrumentation/prod_node_modules /instrumentations/nodejs/node_modules

COPY --from=nodejs-agent-native-community-builder /repos/odigos/agents/nodejs-native-community /instrumentations/nodejs

# .NET
COPY --from=dotnet-builder /dotnet-instrumentation /instrumentations/dotnet
Expand Down
1 change: 1 addition & 0 deletions opentelemetry-helm-charts
Submodule opentelemetry-helm-charts added at f75b28
13 changes: 8 additions & 5 deletions procdiscovery/pkg/inspectors/java/java.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package java

import (
"regexp"
"strings"

"github.com/hashicorp/go-version"

Expand All @@ -12,13 +11,17 @@ import (

type JavaInspector struct{}

const processName = "java"
const JavaVersionRegex = `\d+\.\d+\.\d+\+\d+`

var re = regexp.MustCompile(JavaVersionRegex)
// Matches any file path ending with:
// - "java" (e.g., /usr/bin/java)
// - "javaw" (though less common on Linux)
// - "java" / "javaw" followed by version digits (e.g., java8, java11, java17).
var exeRegex = regexp.MustCompile(`.*/javaw?(?:\d+)?$`)
var versionRegex = regexp.MustCompile(JavaVersionRegex)

func (j *JavaInspector) Inspect(proc *process.Details) (common.ProgrammingLanguage, bool) {
if strings.Contains(proc.ExePath, processName) || strings.Contains(proc.CmdLine, processName) {
if exeRegex.MatchString(proc.ExePath) {
return common.JavaProgrammingLanguage, true
}

Expand All @@ -27,7 +30,7 @@ func (j *JavaInspector) Inspect(proc *process.Details) (common.ProgrammingLangua

func (j *JavaInspector) GetRuntimeVersion(proc *process.Details, containerURL string) *version.Version {
if value, exists := proc.GetDetailedEnvsValue(process.JavaVersionConst); exists {
javaVersion := re.FindString(value)
javaVersion := versionRegex.FindString(value)
return common.GetVersion(javaVersion)
}

Expand Down
Loading