# Request spanning across multiple packages are not consolidated into a single transaction - Java agent

**URL:** <https://discuss.elastic.co/t/request-spanning-across-multiple-packages-are-not-consolidated-into-a-single-transaction-java-agent/166970>\
**Category:** APM\
**Created:** [February 4, 2019, 2:13pm UTC](https://discuss.elastic.co/t/request-spanning-across-multiple-packages-are-not-consolidated-into-a-single-transaction-java-agent/166970 "2019-02-04T14:13:30Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![annrekh](https://avatars.discourse-cdn.com/v4/letter/a/ea666f/32.png) [@annrekh](https://discuss.elastic.co/u/annrekh)\
**Post date:** [February 4, 2019, 2:13pm UTC](https://discuss.elastic.co/t/request-spanning-across-multiple-packages-are-not-consolidated-into-a-single-transaction-java-agent/166970/1 "2019-02-04T14:13:31Z")

</div>

APM Server version: 6.5.0

APM Agent language and version: Java Agent 1.3.0

Ours is a application with multiple modules residing in different packages ,we use web services where each HTTP request spans across different packages to get the desired data.

I have included the java agent and everything works fine when i include a single package in Trace method , but while including multiple packages to drill down to the actual performance bottle neck , the request that spans across multiple packages are not consolidated into a single transaction , but are sensed as independent custom methods .How can i consolidate the methods across different packages into a single request transaction ?

---

<div class="post-metadata">

**Author:** ![felixbarny](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/felixbarny/32/27341_2.png) [@felixbarny](https://discuss.elastic.co/u/felixbarny)\
**Post date:** [February 4, 2019, 2:26pm UTC](https://discuss.elastic.co/t/request-spanning-across-multiple-packages-are-not-consolidated-into-a-single-transaction-java-agent/166970/2 "2019-02-04T14:26:42Z")

</div>

Hi and thanks for using the Java agent 🙂

> [@annrekh](#):
>
> we use web services where each HTTP request spans across different packages to get the desired data.

Which http client are you using for that? We currently support these: [Supported technologies | APM Java Agent Reference [1.x] | Elastic](https://www.elastic.co/guide/en/apm/agent/java/current/supported-technologies-details.html#supported-networking-frameworks)

The next version will also support OkHttp and HttpUrlConnection.

Best,  
Felix

---

<div class="post-metadata">

**Author:** ![annrekh](https://avatars.discourse-cdn.com/v4/letter/a/ea666f/32.png) [@annrekh](https://discuss.elastic.co/u/annrekh)\
**Post date:** [February 5, 2019, 4:52am UTC](https://discuss.elastic.co/t/request-spanning-across-multiple-packages-are-not-consolidated-into-a-single-transaction-java-agent/166970/3 "2019-02-05T04:52:45Z")

</div>

Hi Felix ,

```
        Thanks a lot for the quick reply :) we are using Apache Http Client - 4.5.2 , which is supported by the java agent . As i mentioned i am able to get the correct readings and spans when the request spans within a single package (the spans are consolidated into single request) . The spans are not consolidated into single request only when the http request spans across multiple packages as a part of cross module communication.Please let me know if more detailed information is required.
```

---

<div class="post-metadata">

**Author:** ![felixbarny](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/felixbarny/32/27341_2.png) [@felixbarny](https://discuss.elastic.co/u/felixbarny)\
**Post date:** [February 5, 2019, 9:35am UTC](https://discuss.elastic.co/t/request-spanning-across-multiple-packages-are-not-consolidated-into-a-single-transaction-java-agent/166970/4 "2019-02-05T09:35:19Z")

</div>

Which web framework are you using to handle the HTTP requests? Is that one of the supported ones?

---

<div class="post-metadata">

**Author:** ![annrekh](https://avatars.discourse-cdn.com/v4/letter/a/ea666f/32.png) [@annrekh](https://discuss.elastic.co/u/annrekh)\
**Post date:** [February 5, 2019, 9:56am UTC](https://discuss.elastic.co/t/request-spanning-across-multiple-packages-are-not-consolidated-into-a-single-transaction-java-agent/166970/5 "2019-02-05T09:56:26Z")

</div>

Yes Felix , its Spring web MVC 4.3.5

---

<div class="post-metadata">

**Author:** ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)\
**Post date:** [February 13, 2019, 3:10am UTC](https://discuss.elastic.co/t/request-spanning-across-multiple-packages-are-not-consolidated-into-a-single-transaction-java-agent/166970/6 "2019-02-13T03:10:51Z")

</div>

Hi and thanks too for using the Java Agent

Are

> "the request that spans across multiple packages "

spanning multiple controllers?

Could you provide your agent configuration parameters including the `trace_methods` parameter?

Could you also provide the package names that you are trying to trace?

---

<div class="post-metadata">

**Author:** ![annrekh](https://avatars.discourse-cdn.com/v4/letter/a/ea666f/32.png) [@annrekh](https://discuss.elastic.co/u/annrekh)\
**Post date:** [February 13, 2019, 5:46am UTC](https://discuss.elastic.co/t/request-spanning-across-multiple-packages-are-not-consolidated-into-a-single-transaction-java-agent/166970/7 "2019-02-13T05:46:03Z")

</div>

Hi Stephen ,

```
          Thanks for the reply . Initially to set the context , our package structure is something that looks like this ,

com
	abc
		proj
			core
				user
					bo
						UserBO.java
						Impl
							UserImpl.java
					dao
						userDao.java
						Impl	
							UserDaoImpl.java
						Mapper
							UserMapper.java
						Entity
							UserEntity.java
					service
						UserService.java
					web
						UserController.java
				role
					bo
						RoleBO.java
						Impl	
							RoleBOImpl.java
					dao
						RoleDao.java
						Impl
							RoleDaoImpl.java
						Mapper
							RoleMapper.java
						Entity
							RoleEntity.java
					service
						RoleService.java
					web
						RoleController.java
			common
				work
					bo
						WorkBO.java
						Impl
							WorkBOImpl.java
					dao
						WorkDao.java
						Impl
							WorkDaoImpl.java
						Mapper
							WorkMapper.java
						Entity
							WorkEnity.java
					service
						WorkService.java
					web
						WorkController.java

Implying - com.abc.proj.core.user.bo.impl.UserBOImpl.java
                   com.abc.proj.core.user.web.UserController.java
                   com.abc.proj.common.work.service.WorkService.java

```

I would like to get the span for all the java files involved in a request . A request can invoke the java files in multiple package (ie user , role, work ).The spans are not consolidated into a single transaction when the request invokes java files from multiple packages (ie user and role or user and work).The consolidation happens correctly when the request invokes java classes from a single package say user.My trace method and application package parameters are given below ,

`trace_methods=com.abc.proj.core.user.*#*,com.abc.proj.core.role.*#*,com.abc.proj.common.work.*#*`

`application_packages= com.abc.proj.*`

---

<div class="post-metadata">

**Author:** ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)\
**Post date:** [February 13, 2019, 4:14pm UTC](https://discuss.elastic.co/t/request-spanning-across-multiple-packages-are-not-consolidated-into-a-single-transaction-java-agent/166970/8 "2019-02-13T16:14:26Z")

</div>

A couple more questions / suggestion.

I am still unclear if the request spans multiple controllers or just a single controller?

If you take `trace_methods` completely out are the spans consolidated?

can you try `trace_methods="com.abc.proj.*#*"`

It should recurse ...note the quotes

How are you setting on the command line?... from a startup script, you may need to escape the `\#`?

And if you look at the apm-server logs on start up you should see an error if does not parse the `trace_methods` correctly

---

<div class="post-metadata">

**Author:** ![annrekh](https://avatars.discourse-cdn.com/v4/letter/a/ea666f/32.png) [@annrekh](https://discuss.elastic.co/u/annrekh)\
**Post date:** [February 15, 2019, 7:45am UTC](https://discuss.elastic.co/t/request-spanning-across-multiple-packages-are-not-consolidated-into-a-single-transaction-java-agent/166970/9 "2019-02-15T07:45:19Z")

</div>

Hi Stephen ,

```
           Replies to the queries and suggestions .

```

> I am still unclear if the request spans multiple controllers or just a single controller?

The request spans just a single controller ,because cross-package invocation happens at service layer and not through the controller.

> And if you look at the apm-server logs on start up you should see an error if does not parse the `trace_methods` correctly

Not getting any errors on log with the following trace methods  
trace\_methods=com.abc.proj.core.user._#_,com.abc.proj.core.role._#_,com.abc.proj.common.work._#_

> can you try `trace_methods="com.abc.proj.*#*"`

Throws an error stating invalid trace methods.

> If you take `trace_methods` completely out are the spans consolidated?

No Stephen , its not happening.

> How are you setting on the command line?... from a startup script, you may need to escape the `\#` ?

Sorry dint get this .

---

<div class="post-metadata">

**Author:** ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)\
**Post date:** [February 15, 2019, 5:42pm UTC](https://discuss.elastic.co/t/request-spanning-across-multiple-packages-are-not-consolidated-into-a-single-transaction-java-agent/166970/10 "2019-02-15T17:42:32Z")

</div>

> [@annrekh](#):
>
> > can you try `trace_methods="com.abc.proj.*#*"`
> 
> Throws an error stating invalid trace methods.

Huh it should not.... that is a valid matcher. You can take out the quotes.

See Here for valid matchers: [Core configuration options | APM Java Agent Reference [1.x] | Elastic](https://www.elastic.co/guide/en/apm/agent/java/current/config-core.html#config-trace-methods)

your supplied matchers do not look correct to me see the document they should require `*#*` not just a `#`  
`trace_methods=com.abc.proj.core.user.#,com.abc.proj.core.role.#,com.abc.proj.common.work.#`

If you upgrade to 1.4 you can try

`trace_methods=com.abc.proj.*`

My question at the end was how are you starting the application? From the command line? if so you may need to escape the `#` or quote it.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [March 8, 2019, 1:42pm UTC](https://discuss.elastic.co/t/request-spanning-across-multiple-packages-are-not-consolidated-into-a-single-transaction-java-agent/166970/11 "2019-03-08T13:42:36Z")

</div>

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.
