|
| 1 | +/* |
| 2 | + * Copyright 2024 Google LLC |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +plugins { |
| 17 | + id 'org.springframework.boot' version '2.4.5' |
| 18 | + id 'io.spring.dependency-management' version '1.0.11.RELEASE' |
| 19 | + id 'java' |
| 20 | + id 'application' |
| 21 | + id 'com.google.cloud.tools.jib' |
| 22 | +} |
| 23 | + |
| 24 | +repositories { |
| 25 | + mavenCentral() |
| 26 | +} |
| 27 | + |
| 28 | +description = 'Java Spring application instrumented with OpenTelemetry and enabled resource detection' |
| 29 | + |
| 30 | +jar { |
| 31 | + manifest { |
| 32 | + attributes( |
| 33 | + 'Main-Class': 'com.google.cloud.opentelemetry.example.spring.Main' |
| 34 | + ) |
| 35 | + } |
| 36 | +} |
| 37 | + |
| 38 | +// OpenTelemetry Autoconfigure module can be configured using system properties |
| 39 | +def autoconf_config = [ |
| 40 | + '-Dotel.resource.attributes=gcp.project_id=otel-test-sharmapranav', |
| 41 | + '-Dotel.traces.exporter=google_cloud_trace', |
| 42 | + '-Dotel.metrics.exporter=google_cloud_monitoring,logging', |
| 43 | + '-Dotel.logs.exporter=none', |
| 44 | + '-Dotel.java.global-autoconfigure.enabled=true', |
| 45 | + '-Dotel.service.name=spring-example-service', |
| 46 | +] |
| 47 | + |
| 48 | +jib { |
| 49 | + from.image = "gcr.io/distroless/java-debian10:11" |
| 50 | + containerizingMode = "packaged" |
| 51 | + container.ports = ["8080"] |
| 52 | + container.jvmFlags = autoconf_config as List |
| 53 | +} |
| 54 | + |
| 55 | +// convenience task to build and run app with correct system properties |
| 56 | +tasks.register('runApp', JavaExec) { |
| 57 | + group = "Execution" |
| 58 | + description = "Builds and runs the spring application's execuable JAR" |
| 59 | + |
| 60 | + dependsOn tasks.bootJar |
| 61 | + classpath = files('build/libs/examples-spring-0.1.0-SNAPSHOT.jar') |
| 62 | + jvmArgs = autoconf_config |
| 63 | +} |
| 64 | + |
| 65 | +dependencies { |
| 66 | + implementation(libraries.opentelemetry_api) |
| 67 | + implementation(libraries.opentelemetry_sdk) |
| 68 | + implementation(libraries.google_cloud_trace) |
| 69 | + implementation(libraries.spring_boot_starter_web) |
| 70 | + // using autoconfigure to detect resources |
| 71 | + implementation(libraries.opentelemetry_sdk_autoconf) |
| 72 | + implementation(libraries.opentelemetry_autoconfigure_spi) |
| 73 | + // resource detection module |
| 74 | + runtimeOnly(libraries.opentelemetry_gcp_resources) |
| 75 | + // exporter dependencies |
| 76 | + implementation project(':exporter-trace') |
| 77 | + implementation project(':exporter-metrics') |
| 78 | + // auto exporter makes Google Cloud exporters available to autoconfigure module |
| 79 | + implementation project(':exporter-auto') |
| 80 | + // this helps in debugging as it outputs all export to std out |
| 81 | + implementation 'io.opentelemetry:opentelemetry-exporter-logging:1.33.0' |
| 82 | +} |
| 83 | + |
| 84 | +test { |
| 85 | + useJUnitPlatform() |
| 86 | +} |
0 commit comments