MCPcopy Index your code
hub / github.com/cloudfoundry/java-buildpack / Finalize

Method Finalize

src/java/frameworks/new_relic.go:124–173  ·  view source on GitHub ↗

Finalize performs final New Relic configuration

()

Source from the content-addressed store, hash-verified

122
123// Finalize performs final New Relic configuration
124func (n *NewRelicFramework) Finalize() error {
125 // Get buildpack index for multi-buildpack support
126 depsIdx := n.context.Stager.DepsIdx()
127
128 // Find the actual New Relic agent jar at staging time
129 agentDir := filepath.Join(n.context.Stager.DepDir(), "new_relic_agent")
130 agentJarPath, err := n.findNewRelicAgent(agentDir)
131 if err != nil {
132 return fmt.Errorf("failed to locate newrelic.jar: %w", err)
133 }
134
135 // Build runtime path using $DEPS_DIR
136 relPath, err := filepath.Rel(n.context.Stager.DepDir(), agentJarPath)
137 if err != nil {
138 return fmt.Errorf("failed to compute relative path: %w", err)
139 }
140 runtimeAgentPath := filepath.Join(fmt.Sprintf("$DEPS_DIR/%s", depsIdx), relPath)
141
142 // Add javaagent to JAVA_OPTS
143 javaOpts := fmt.Sprintf("-javaagent:%s", runtimeAgentPath)
144
145 // Get New Relic configuration from service binding
146 vcapServices, _ := GetVCAPServices()
147 service := vcapServices.GetService("newrelic")
148
149 // If not found by label, try user-provided services (Docker platform)
150 if service == nil {
151 service = vcapServices.GetServiceByNamePattern("newrelic")
152 }
153
154 if service != nil {
155 // Add license key from service credentials
156 if licenseKey, ok := service.Credentials["licenseKey"].(string); ok && licenseKey != "" {
157 javaOpts += fmt.Sprintf(" -Dnewrelic.config.license_key=%s", licenseKey)
158 }
159
160 // Add app name from service name
161 if service.Name != "" {
162 javaOpts += fmt.Sprintf(" -Dnewrelic.config.app_name='%s'", service.Name)
163 }
164 }
165
166 // Write to .opts file using priority 35
167 if err := writeJavaOptsFile(n.context, 35, "new_relic", javaOpts); err != nil {
168 return fmt.Errorf("failed to write java_opts file: %w", err)
169 }
170
171 n.context.Log.Debug("New Relic Agent configured (priority 35)")
172 return nil
173}
174
175func (n *NewRelicFramework) DependencyIdentifier() string {
176 return "newrelic"

Callers

nothing calls this directly

Calls 7

findNewRelicAgentMethod · 0.95
writeJavaOptsFileFunction · 0.85
GetServiceMethod · 0.80
GetVCAPServicesFunction · 0.70
DepsIdxMethod · 0.65
DepDirMethod · 0.65

Tested by

no test coverage detected