Skip to content

Commit

Permalink
Merge pull request #9 from grafana/java_agent_linter_fix
Browse files Browse the repository at this point in the history
  • Loading branch information
grcevski authored Feb 27, 2025
2 parents 039c17d + 9283c78 commit 0a86c8b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
22 changes: 14 additions & 8 deletions pkg/internal/otelsdk/sdk_inject.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"bufio"
_ "embed"
"fmt"
"io/ioutil"
"log/slog"
"maps"
"os"
Expand Down Expand Up @@ -117,13 +116,17 @@ func (i *SDKInjector) extractAgent(ie *ebpf.Instrumentable) (string, error) {

i.log.Info("found injection directory for process", "pid", ie.FileInfo.Pid, "path", fullTempDir)

agentPath := filepath.Join(fullTempDir, "grafana-opentelemetry-java.jar")
const agentFile = "grafana-opentelemetry-java.jar"

if err = ioutil.WriteFile(agentPath, _agentBytes, 0644); err != nil {
agentPathHost := filepath.Join(fullTempDir, agentFile)

if err = os.WriteFile(agentPathHost, _agentBytes, 0644); err != nil {
return "", fmt.Errorf("error writing file: %w", err)
}

return agentPath, nil
agentPathContainer := filepath.Join(tempDir, agentFile)

return agentPathContainer, nil
}

func expandHeadersWithAuth(options map[string]string, key string, value string) {
Expand Down Expand Up @@ -203,9 +206,12 @@ func (i *SDKInjector) attachJDKAgent(pid int32, path string, cfg *beyla.Config)
return fmt.Errorf("error parsing OTLP options")
}

options := flattenOptionsMap(opts)
// this option needs to appear first in the list
options := "grafana.otel.debug-agent-startup=true"
flattenedMap := flattenOptionsMap(opts)

if len(options) > 0 {
if len(flattenedMap) > 0 {
options = options + "," + flattenedMap
i.log.Info("passing options to the JVM agent", "options", options)
}

Expand Down Expand Up @@ -244,8 +250,8 @@ func (i *SDKInjector) jdkAgentAlreadyLoaded(pid int32) (bool, error) {

scanner := bufio.NewScanner(out)
for scanner.Scan() {
// We check for io.opentelemetry.javaagent.OpenTelemetryAgent/0x<address>
if strings.Contains(scanner.Text(), "io.opentelemetry.javaagent.OpenTelemetryAgent/0x") {
// We check for com.grafana.GrafanaOpenTelemetryAgent/0x<address>
if strings.Contains(scanner.Text(), "com.grafana.GrafanaOpenTelemetryAgent/0x") {
return true, nil
}
}
Expand Down
2 changes: 1 addition & 1 deletion test/integration/red_test_java.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func testREDMetricsForJavaOTelSDK(t *testing.T, urls []string) {
results, err = pq.Query(`http_server_request_duration_seconds_count{` +
`http_request_method="GET",` +
`http_response_status_code="204",` +
`telemetry_distro_name="opentelemetry-java-instrumentation",` +
`telemetry_distro_name="grafana-opentelemetry-java",` +
`service_name="greeting-service",` +
`http_route="/greeting"}`)
require.NoError(t, err)
Expand Down

0 comments on commit 0a86c8b

Please sign in to comment.