Skip to content

Commit 20e5f71

Browse files
committed
Merge branch 'main' into Improve-Logging
2 parents 1d94b4c + 2ae2827 commit 20e5f71

File tree

4 files changed

+14
-13
lines changed

4 files changed

+14
-13
lines changed

core/src/main/java/com/sap/ai/sdk/core/AiCoreService.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,7 @@ public class AiCoreService {
4343

4444
/** The default constructor. */
4545
public AiCoreService() {
46-
val resolver = new DestinationResolver();
47-
this.baseDestinationResolver = resolver::getDestination;
48-
this.deploymentResolver = new DeploymentResolver(this);
46+
this(new DestinationResolver()::getDestination);
4947
}
5048

5149
AiCoreService(@Nonnull final Supplier<HttpDestination> baseDestinationResolver) {

core/src/main/java/com/sap/ai/sdk/core/AiCoreServiceKeyAccessor.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import lombok.AllArgsConstructor;
1818
import lombok.extern.slf4j.Slf4j;
1919
import lombok.val;
20+
import org.slf4j.event.Level;
2021

2122
/**
2223
* Loads an AI Core service key from the "AICORE_SERVICE_KEY" environment variable with support for
@@ -27,10 +28,13 @@
2728
class AiCoreServiceKeyAccessor implements ServiceBindingAccessor {
2829
static final String ENV_VAR_KEY = "AICORE_SERVICE_KEY";
2930

31+
private static final Lazy<Dotenv> DEFAULT_DOTENV =
32+
Lazy.of(() -> Dotenv.configure().ignoreIfMissing().ignoreIfMalformed().load());
33+
3034
private final Lazy<Dotenv> dotenv;
3135

3236
AiCoreServiceKeyAccessor() {
33-
this(Dotenv.configure().ignoreIfMissing().ignoreIfMalformed());
37+
this(DEFAULT_DOTENV);
3438
}
3539

3640
AiCoreServiceKeyAccessor(@Nonnull final DotenvBuilder dotenvBuilder) {
@@ -41,6 +45,7 @@ class AiCoreServiceKeyAccessor implements ServiceBindingAccessor {
4145
@Override
4246
public List<ServiceBinding> getServiceBindings() throws ServiceBindingAccessException {
4347
final String serviceKey;
48+
final Level logLevel = dotenv.isEvaluated() ? Level.TRACE : Level.INFO;
4449
try {
4550
serviceKey = dotenv.get().get(ENV_VAR_KEY);
4651
} catch (Exception e) {
@@ -50,13 +55,11 @@ public List<ServiceBinding> getServiceBindings() throws ServiceBindingAccessExce
5055
log.debug("No service key found in environment variable {}", ENV_VAR_KEY);
5156
return List.of();
5257
}
53-
log.info(
54-
"""
55-
Found a service key in environment variable {}.
56-
Using a service key is recommended for local testing only.
57-
Bind the AI Core service to the application for productive usage.
58-
""",
59-
ENV_VAR_KEY);
58+
final String logMessage =
59+
"Found a service key in environment variable {}. "
60+
+ "Using a service key is recommended for local testing only."
61+
+ "Bind the AI Core service to the application for productive usage.";
62+
log.atLevel(logLevel).log(logMessage, ENV_VAR_KEY);
6063

6164
val binding = createServiceBinding(serviceKey);
6265
return List.of(binding);

docs/release_notes.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
### 📈 Improvements
1818

1919
- [Core] If the AI Core credentials used are missing an explicit `credential-type` but `clientid` and `clientsecret` are present then `"credential-type": "binding-secret"` is inferred automatically.
20-
20+
- [Core] Log message about "service key in environment variable" to `INFO` level only once.
2121

2222
### 🐛 Fixed Issues
2323

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
<maven.compiler.proc>full</maven.compiler.proc>
5656
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
5757
<project.build.outputTimestamp>2025-04-03T13:23:00Z</project.build.outputTimestamp>
58-
<cloud-sdk.version>5.23.0</cloud-sdk.version>
58+
<cloud-sdk.version>5.24.0</cloud-sdk.version>
5959
<junit-jupiter.version>6.0.0</junit-jupiter.version>
6060
<wiremock.version>3.13.1</wiremock.version>
6161
<assertj-core.version>3.27.6</assertj-core.version>

0 commit comments

Comments
 (0)