@@ -19,7 +19,6 @@ import (
19
19
"github.com/opentracing/opentracing-go"
20
20
21
21
"go.undefinedlabs.com/scopeagent/config"
22
- "go.undefinedlabs.com/scopeagent/env"
23
22
scopeError "go.undefinedlabs.com/scopeagent/errors"
24
23
"go.undefinedlabs.com/scopeagent/instrumentation"
25
24
"go.undefinedlabs.com/scopeagent/runner"
64
63
65
64
testingModeFrequency = time .Second
66
65
nonTestingModeFrequency = time .Minute
66
+
67
+ cfg = config .Get ()
67
68
)
68
69
69
70
func WithApiKey (apiKey string ) Option {
@@ -194,13 +195,13 @@ func NewAgent(options ...Option) (*Agent, error) {
194
195
agent .logger = log .New (ioutil .Discard , "" , 0 )
195
196
}
196
197
197
- agent .debugMode = agent .debugMode || env . ScopeDebug . Value
198
+ agent .debugMode = agent .debugMode || * cfg . Debug
198
199
199
200
configProfile := GetConfigCurrentProfile ()
200
201
201
202
if agent .apiKey == "" || agent .apiEndpoint == "" {
202
- if dsn , set := env . ScopeDsn . Tuple (); set && dsn != "" {
203
- dsnApiKey , dsnApiEndpoint , dsnErr := parseDSN (dsn )
203
+ if cfg . Dsn != nil && * cfg . Dsn != "" {
204
+ dsnApiKey , dsnApiEndpoint , dsnErr := parseDSN (* cfg . Dsn )
204
205
if dsnErr != nil {
205
206
agent .logger .Printf ("Error parsing dsn value: %v\n " , dsnErr )
206
207
} else {
@@ -213,8 +214,8 @@ func NewAgent(options ...Option) (*Agent, error) {
213
214
}
214
215
215
216
if agent .apiKey == "" {
216
- if apiKey , set := env . ScopeApiKey . Tuple (); set && apiKey != "" {
217
- agent .apiKey = apiKey
217
+ if cfg . ApiKey != nil && * cfg . ApiKey != "" {
218
+ agent .apiKey = * cfg . ApiKey
218
219
} else if configProfile != nil {
219
220
agent .logger .Println ("API key found in the native app configuration" )
220
221
agent .apiKey = configProfile .ApiKey
@@ -226,12 +227,13 @@ func NewAgent(options ...Option) (*Agent, error) {
226
227
}
227
228
228
229
if agent .apiEndpoint == "" {
229
- if endpoint , set := env . ScopeApiEndpoint . Tuple (); set && endpoint != "" {
230
- agent .apiEndpoint = endpoint
230
+ if cfg . ApiEndpoint != nil && * cfg . ApiEndpoint != "" {
231
+ agent .apiEndpoint = * cfg . ApiEndpoint
231
232
} else if configProfile != nil {
232
233
agent .logger .Println ("API endpoint found in the native app configuration" )
233
234
agent .apiEndpoint = configProfile .ApiEndpoint
234
235
} else {
236
+ endpoint := "https://app.scope.dev"
235
237
agent .logger .Printf ("using default endpoint: %v\n " , endpoint )
236
238
agent .apiEndpoint = endpoint
237
239
}
@@ -271,13 +273,19 @@ func NewAgent(options ...Option) (*Agent, error) {
271
273
agent .metadata [tags .GoVersion ] = runtime .Version ()
272
274
273
275
// Service name
274
- addElementToMapIfEmpty (agent .metadata , tags .Service , env .ScopeService .Value )
276
+ if cfg .Service != nil {
277
+ addElementToMapIfEmpty (agent .metadata , tags .Service , * cfg .Service )
278
+ }
275
279
276
280
// Configurations
277
- addElementToMapIfEmpty (agent .metadata , tags .ConfigurationKeys , env .ScopeConfiguration .Value )
281
+ if cfg .Configuration != nil {
282
+ addElementToMapIfEmpty (agent .metadata , tags .ConfigurationKeys , cfg .Configuration )
283
+ }
278
284
279
285
// Metadata
280
- addToMapIfEmpty (agent .metadata , env .ScopeMetadata .Value )
286
+ if cfg .Metadata != nil {
287
+ addToMapIfEmpty (agent .metadata , cfg .Metadata )
288
+ }
281
289
282
290
// Git data
283
291
addToMapIfEmpty (agent .metadata , getGitInfoFromEnv ())
@@ -292,26 +300,26 @@ func NewAgent(options ...Option) (*Agent, error) {
292
300
agent .metadata [tags .Dependencies ] = getDependencyMap ()
293
301
294
302
// Expand '~' in source root
295
- var sourceRoot string
296
303
if sRoot , ok := agent .metadata [tags .SourceRoot ]; ok {
297
304
if sRootEx , err := homedir .Expand (sRoot .(string )); err == nil {
298
- sourceRoot = sRootEx
299
305
agent .metadata [tags .SourceRoot ] = sRootEx
300
306
}
301
307
}
302
308
303
309
if ! agent .testingMode {
304
- if env . ScopeTestingMode . IsSet {
305
- agent .testingMode = env . ScopeTestingMode . Value
310
+ if cfg . TestingMode != nil {
311
+ agent .testingMode = * cfg . TestingMode
306
312
} else {
307
313
agent .testingMode = agent .metadata [tags .CI ].(bool )
308
314
}
309
315
}
310
316
311
- if agent .failRetriesCount == 0 {
312
- agent .failRetriesCount = env .ScopeTestingFailRetries .Value
317
+ if agent .failRetriesCount == 0 && cfg .Instrumentation .TestsFrameworks .FailRetries != nil {
318
+ agent .failRetriesCount = * cfg .Instrumentation .TestsFrameworks .FailRetries
319
+ }
320
+ if cfg .Instrumentation .TestsFrameworks .PanicAsFail != nil {
321
+ agent .panicAsFail = agent .panicAsFail || * cfg .Instrumentation .TestsFrameworks .PanicAsFail
313
322
}
314
- agent .panicAsFail = agent .panicAsFail || env .ScopeTestingPanicAsFail .Value
315
323
316
324
if agent .debugMode {
317
325
agent .logMetadata ()
@@ -339,10 +347,7 @@ func NewAgent(options ...Option) (*Agent, error) {
339
347
})
340
348
instrumentation .SetTracer (agent .tracer )
341
349
instrumentation .SetLogger (agent .logger )
342
- if err := config .Load (path .Join (sourceRoot , "scope.yml" )); err != nil {
343
- agent .logger .Println (err )
344
- }
345
- if agent .setGlobalTracer || env .ScopeTracerGlobal .Value {
350
+ if agent .setGlobalTracer || (cfg .Tracer .Global != nil && * cfg .Tracer .Global ) {
346
351
opentracing .SetGlobalTracer (agent .Tracer ())
347
352
}
348
353
@@ -408,8 +413,8 @@ func generateAgentID() string {
408
413
}
409
414
410
415
func getLogPath () (string , error ) {
411
- if env . ScopeLoggerRoot . IsSet {
412
- return env . ScopeLoggerRoot . Value , nil
416
+ if cfg . Logger . Root != nil {
417
+ return * cfg . Logger . Root , nil
413
418
}
414
419
415
420
logFolder := ""
0 commit comments