Skip to content

Commit 0e77a90

Browse files
author
Shadi Ramadan
committed
Initial commit
0 parents  commit 0e77a90

File tree

7 files changed

+182
-0
lines changed

7 files changed

+182
-0
lines changed

.gitignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
*.class
2+
*.log
3+
4+
target
5+
project/project
6+
project/target
7+
.cache
8+
.classpath
9+
.project
10+
.settings
11+
bin

LICENSE.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
The MIT License (MIT)
3+
4+
Copyright (c) 2019 Shadi Ramadan
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in all
14+
copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
SOFTWARE.

README.md

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# sbt-elastic-apm
2+
3+
[![Download](https://api.bintray.com/packages/shadiramadan/sbt-plugins/sbt-elastic-apm/images/download.svg)](https://bintray.com/shadiramadan/sbt-plugins/sbt-elastic-apm/_latestVersion)
4+
5+
Add the Elastic APM Java Agent to your sbt project.
6+
7+
This project is heavily inspired by the [sbt-datadog](https://github.com/Colisweb/sbt-datadog) project.
8+
9+
Given the similar nature of the projects this plugin was quick to setup. Merci [@guizmaii](https://github.com/guizmaii)!
10+
11+
Prerequisites
12+
-------------
13+
The plugin assumes that sbt-native-packager has been included in your SBT build configuration.
14+
This can be done by adding the plugin following instructions at http://www.scala-sbt.org/sbt-native-packager/ or by adding
15+
another plugin that includes and initializes it.
16+
17+
Installation
18+
------------
19+
20+
Add the following to your `project/plugins.sbt` file:
21+
22+
```scala
23+
resolvers += Resolver.bintrayIvyRepo("shadiramadan", "sbt-plugins")
24+
25+
addSbtPlugin("com.shadiramadan.sbt" % "sbt-elastic-apm" % "1.0.0")
26+
```
27+
28+
To enable the Elastic APM for your project, add the `ElasticApmPlugin` auto-plugin to your project.
29+
30+
```scala
31+
enablePlugins(ElasticApmPlugin)
32+
```
33+
34+
Configuration
35+
-------------
36+
37+
#### `elasticApmVersion`
38+
39+
To use a specific Elastic APM Java Agent version, add the following to your `build.sbt` file:
40+
41+
```scala
42+
elasticApmVersion := "1.6.1"
43+
```
44+
45+
#### `elasticApmServiceName`
46+
47+
By default, the agent will use the sbt project `name` value as `elastic.apm.service_name`.
48+
49+
To use another value, add the following to your `build.sbt` file:
50+
51+
```scala
52+
elasticApmServiceName := "another name"
53+
```
54+
55+
#### `elasticApmAgentApplicationPackages`
56+
57+
By default, the agent `elastic.apm.application_packages` value is `com.example`.
58+
59+
To use another value, add the following to your `build.sbt` file:
60+
61+
```scala
62+
elasticApmAgentApplicationPackages := Seq("com.example")
63+
```
64+
65+
#### `elasticApmAgentServerUrls`
66+
67+
By default, the agent `elastic.apm.server_urls` value is `http://localhost:8200`.
68+
69+
To use another value, add the following to your `build.sbt` file:
70+
71+
```scala
72+
elasticApmAgentServerUrls := Seq(url("http://localhost:8200"))
73+
```
74+

build.sbt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name := "sbt-elastic-apm"
2+
organization := "com.shadiramadan.sbt"
3+
version := "1.0.0"
4+
5+
licenses := Seq("MIT" -> url("http://opensource.org/licenses/MIT"))
6+
homepage := Some(url("https://github.com/shadiramadan/sbt-elastic-apm"))
7+
8+
credentials += Credentials(Path.userHome / ".bintray" / ".credentials")
9+
10+
enablePlugins(SbtPlugin)
11+
12+
addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.3.20" % "provided")
13+
14+
bintrayPackageLabels := Seq("sbt", "plugin")
15+
16+
bintrayVcsUrl := Some("https://github.com/shadiramadan/sbt-elastic-apm")
17+
18+
bintrayReleaseOnPublish := false

project/build.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
sbt.version=1.2.8

project/plugins.sbt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
addSbtPlugin("org.foundweekends" % "sbt-bintray" % "0.5.1")
2+
addSbtPlugin("com.timushev.sbt" % "sbt-updates" % "0.4.0")
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package com.shadiramadan.sbt.elastic.apm
2+
3+
import sbt._
4+
import sbt.Keys._
5+
import sbt.plugins.JvmPlugin
6+
import com.typesafe.sbt.SbtNativePackager._
7+
import com.typesafe.sbt.packager.archetypes.scripts.BashStartScriptPlugin.autoImport.bashScriptExtraDefines
8+
import com.typesafe.sbt.packager.archetypes.scripts.{BashStartScriptPlugin, BatStartScriptPlugin}
9+
import sbt.librarymanagement.DependencyFilter
10+
11+
object ElasticApmPlugin extends AutoPlugin {
12+
13+
override def trigger = allRequirements
14+
override def requires = JvmPlugin && BashStartScriptPlugin && BatStartScriptPlugin
15+
16+
object autoImport {
17+
lazy val elasticApmVersion = settingKey[String]("Elastic APM Agent version")
18+
lazy val elasticApmJavaAgent = taskKey[File]("Elastic APM agent jar location")
19+
lazy val elasticApmServiceName = taskKey[String](
20+
"This is used to keep all the errors and transactions of your service together and is the primary filter in the Elastic APM user interface. The default value is the sbt project name.")
21+
lazy val elasticApmAgentApplicationPackages = taskKey[Seq[String]](
22+
"Used to determine whether a stack trace frame is an in-app frame or a library frame. Multiple packages can be set as a comma-separated list. Setting this option can also improve the startup time.")
23+
lazy val elasticApmAgentServerUrls = taskKey[Seq[URL]](
24+
"The URLs must be fully qualified, including protocol (http or https) and port.")
25+
}
26+
27+
import autoImport._
28+
29+
val ElasticApmConfig = config("elastic-apm-agent").hide
30+
31+
override lazy val projectSettings = Seq(
32+
ivyConfigurations += ElasticApmConfig,
33+
elasticApmVersion := "1.6.1",
34+
elasticApmJavaAgent := findElasticApmJavaAgent(update.value),
35+
elasticApmServiceName := name.value,
36+
elasticApmAgentApplicationPackages := Seq("com.example"),
37+
elasticApmAgentServerUrls := Seq(url("http://localhost:8200")),
38+
libraryDependencies += "co.elastic.apm" % "elastic-apm-agent" % elasticApmVersion.value % ElasticApmConfig,
39+
mappings in Universal += elasticApmJavaAgent.value -> "elasticApm/elastic-apm-agent.jar",
40+
bashScriptExtraDefines += """addJava "-javaagent:${app_home}/../elasticApm/elastic-apm-agent.jar"""",
41+
bashScriptExtraDefines += s"""addJava "-Delastic.apm.service_name=${elasticApmServiceName.value}"""",
42+
bashScriptExtraDefines += s"""addJava "-Delastic.apm.application_packages=${elasticApmAgentApplicationPackages.value.mkString(",")}"""",
43+
bashScriptExtraDefines += s"""addJava "-Delastic.apm.server_urls=${elasticApmAgentServerUrls.value.mkString(",")}""""
44+
)
45+
46+
private[this] def findElasticApmJavaAgent(report: UpdateReport) = report.matching(elasticApmFilter).head
47+
48+
private[this] val elasticApmFilter: DependencyFilter =
49+
configurationFilter("elastic-apm-agent") && artifactFilter(`type` = "jar")
50+
51+
override lazy val buildSettings = Seq()
52+
53+
override lazy val globalSettings = Seq()
54+
}

0 commit comments

Comments
 (0)