diff --git a/odiglet/debug.Dockerfile b/odiglet/debug.Dockerfile index 5899470bef..6695ffac6b 100644 --- a/odiglet/debug.Dockerfile +++ b/odiglet/debug.Dockerfile @@ -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 ######### # @@ -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; \ @@ -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/ @@ -89,7 +99,7 @@ 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 @@ -97,7 +107,7 @@ 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 @@ -105,9 +115,7 @@ RUN chmod 644 /instrumentations/java/javaagent.jar 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 diff --git a/procdiscovery/pkg/inspectors/java/java.go b/procdiscovery/pkg/inspectors/java/java.go index d58541a7f2..8c756060a5 100644 --- a/procdiscovery/pkg/inspectors/java/java.go +++ b/procdiscovery/pkg/inspectors/java/java.go @@ -1,8 +1,8 @@ package java import ( + "path/filepath" "regexp" - "strings" "github.com/hashicorp/go-version" @@ -12,13 +12,18 @@ import ( type JavaInspector struct{} -const processName = "java" const JavaVersionRegex = `\d+\.\d+\.\d+\+\d+` -var re = regexp.MustCompile(JavaVersionRegex) +var versionRegex = 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+)?$`) func (j *JavaInspector) Inspect(proc *process.Details) (common.ProgrammingLanguage, bool) { - if strings.Contains(proc.ExePath, processName) || strings.Contains(proc.CmdLine, processName) { + if exeRegex.MatchString(filepath.Base(proc.ExePath)) { return common.JavaProgrammingLanguage, true } @@ -27,7 +32,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) }