Enabling tracing in production

classic Classic list List threaded Threaded
13 messages Options
Reply | Threaded
Open this post in threaded view
|

Enabling tracing in production

huntc
Hi there,

I'm having difficulty understanding how the tracing facility can be applied at runtime in production; perhaps it cannot be.

If I declare the following in my Spring context:

<bean id="camelTracer" class="org.apache.camel.processor.interceptor.Tracer" />

...and nothing else at all, then tracing is enabled.

So how do I then turn off tracing for production mode without having to modify my context?

If I declare 'trace="false"' on my context declaration then it does not appear to be overridden by the -trace option on the command line... Thus I cannot by default declare tracing as off and then enable it at runtime by changing my startup.

Thanks for any help.

Kind regards,
Christopher
Reply | Threaded
Open this post in threaded view
|

Re: Enabling tracing in production

Richard Kettelerij
You don't have to add a Tracer to your Spring context yourself. Camel adds one automatically if you have a CamelContext declared in Spring. Also your don't have to do anything with the "trace" option in your Spring context.

I find that the easiest way to enable/disable tracing in production is through JMX. Just navigate to the CamelContext MBean and modify the "tracing" attribute. Additionally you can determine what should be traced by modifying a few options in the Tracer MBean.
Reply | Threaded
Open this post in threaded view
|

Re: Enabling tracing in production

Bengt Rodehav
I have a similar situation but I'm not using Spring - I use Java DSL and
iPOJO.

I have my own tracer that I can publish as an OSGi service using iPOJO. I
want to accomplish the following. My other services shall have optional
service dependencies to my tracer. This means that if my custom tracer is
available then it should be used, otherwise the default tracer should be
used.

However, just publishing my tracer and requiring it in my other components
does not automatically cause Camel to use it. I have to to the following:

        getContext().addInterceptStrategy(mTracer);

        getContext().setTracing(false);


In other words I explicitly set my tracer to be used, I then disable tracing
since the first line seems to automatically enable tracing. I then use JMX
to enable/disable tracing. I was hoping the above two lines were unnecessary
and that merely the existence of a tracer should cause Camel to use it. Is
that a Spring specific functionality? I was hoping that any way that an OSGi
service was published/consumed would work?

/Bengt

2010/10/30 Richard Kettelerij <[hidden email]>

>
> You don't have to add a Tracer to your Spring context yourself. Camel adds
> one automatically if you have a CamelContext declared in Spring. Also your
> don't have to do anything with the "trace" option in your Spring context.
>
> I find that the easiest way to enable/disable tracing in production is
> through JMX. Just navigate to the CamelContext MBean and modify the
> "tracing" attribute. Additionally you can determine what should be traced
> by
> modifying a few options in the Tracer MBean.
>
> -----
> Richard Kettelerij,
> http://github.com/rkettelerij
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/Enabling-tracing-in-production-tp3243013p3243143.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
Reply | Threaded
Open this post in threaded view
|

Re: Enabling tracing in production

huntc
In reply to this post by Richard Kettelerij
Richard Kettelerij wrote
You don't have to add a Tracer to your Spring context yourself. Camel adds one automatically if you have a CamelContext declared in Spring. Also your don't have to do anything with the "trace" option in your Spring context.
This was not my experience. Are you certain?

I find that the easiest way to enable/disable tracing in production is through JMX. Just navigate to the CamelContext MBean and modify the "tracing" attribute. Additionally you can determine what should be traced by modifying a few options in the Tracer MBean.
That's a good idea. Thanks.
Reply | Threaded
Open this post in threaded view
|

Re: Enabling tracing in production

Bengt Rodehav
In reply to this post by Bengt Rodehav
Another problem I have is to reconfigure my tracer "on the fly". I was
hoping to use an OSGi configuration to configure my tracer.

My tracer presently extends org.apache.camel.processor.interceptor.Tracer
but allow me to configure the tracer; e g whether or not the body should be
included in the trace or not. I do that as follows:

    DefaultTraceFormatter formatter = new DefaultTraceFormatter();

    formatter.setShowBody(mIncludeBody);

    setFormatter(formatter);


The "mIncludeBody" is taken from an OSGi configuration parameter. I do the
above once in the constructor. That works and my configuration parameter
determines whether the body is included or not.

However, when I later change my configuration, the new value does not seem
to take effect. I can see that the above code is run (with the correct
configuration parameter) but the behavior of the tracer doesn't change
accordingly.

Is it possible to change the formatter of a tracer after it has been
constructed?

/Bengt


2010/10/30 Bengt Rodehav <[hidden email]>

> I have a similar situation but I'm not using Spring - I use Java DSL and
> iPOJO.
>
> I have my own tracer that I can publish as an OSGi service using iPOJO. I
> want to accomplish the following. My other services shall have optional
> service dependencies to my tracer. This means that if my custom tracer is
> available then it should be used, otherwise the default tracer should be
> used.
>
> However, just publishing my tracer and requiring it in my other components
> does not automatically cause Camel to use it. I have to to the following:
>
>         getContext().addInterceptStrategy(mTracer);
>
>         getContext().setTracing(false);
>
>
> In other words I explicitly set my tracer to be used, I then disable
> tracing since the first line seems to automatically enable tracing. I then
> use JMX to enable/disable tracing. I was hoping the above two lines were
> unnecessary and that merely the existence of a tracer should cause Camel to
> use it. Is that a Spring specific functionality? I was hoping that any way
> that an OSGi service was published/consumed would work?
>
> /Bengt
>
> 2010/10/30 Richard Kettelerij <[hidden email]>
>
>
>> You don't have to add a Tracer to your Spring context yourself. Camel adds
>> one automatically if you have a CamelContext declared in Spring. Also your
>> don't have to do anything with the "trace" option in your Spring context.
>>
>> I find that the easiest way to enable/disable tracing in production is
>> through JMX. Just navigate to the CamelContext MBean and modify the
>> "tracing" attribute. Additionally you can determine what should be traced
>> by
>> modifying a few options in the Tracer MBean.
>>
>> -----
>> Richard Kettelerij,
>> http://github.com/rkettelerij
>> --
>> View this message in context:
>> http://camel.465427.n5.nabble.com/Enabling-tracing-in-production-tp3243013p3243143.html
>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>
>
>
Reply | Threaded
Open this post in threaded view
|

Re: Enabling tracing in production

Willem.Jiang
Administrator
In reply to this post by Bengt Rodehav
On 10/30/10 4:49 PM, Bengt Rodehav wrote:

> I have a similar situation but I'm not using Spring - I use Java DSL and
> iPOJO.
>
> I have my own tracer that I can publish as an OSGi service using iPOJO. I
> want to accomplish the following. My other services shall have optional
> service dependencies to my tracer. This means that if my custom tracer is
> available then it should be used, otherwise the default tracer should be
> used.
>
> However, just publishing my tracer and requiring it in my other components
> does not automatically cause Camel to use it. I have to to the following:
>
>          getContext().addInterceptStrategy(mTracer);
>
>          getContext().setTracing(false);
>
>
> In other words I explicitly set my tracer to be used, I then disable tracing
> since the first line seems to automatically enable tracing. I then use JMX
> to enable/disable tracing. I was hoping the above two lines were unnecessary
> and that merely the existence of a tracer should cause Camel to use it. Is
> that a Spring specific functionality? I was hoping that any way that an OSGi
> service was published/consumed would work?

If you take a look at the code of
AbstractCamelContextFactoryBean.afterPropertiesSet() which is used to
set the camel context from the sprint configuration, you will find it
calls the same code.

If you don't want to write upper code twice, you may need to write a
Factory to create the camel context instance in the same way and look up
the tracer from the OSGi service registry.

[1]https://svn.apache.org/repos/asf/camel/trunk/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBean.java

>
> /Bengt
>
> 2010/10/30 Richard Kettelerij<[hidden email]>
>
>>
>> You don't have to add a Tracer to your Spring context yourself. Camel adds
>> one automatically if you have a CamelContext declared in Spring. Also your
>> don't have to do anything with the "trace" option in your Spring context.
>>
>> I find that the easiest way to enable/disable tracing in production is
>> through JMX. Just navigate to the CamelContext MBean and modify the
>> "tracing" attribute. Additionally you can determine what should be traced
>> by
>> modifying a few options in the Tracer MBean.
>>
>> -----
>> Richard Kettelerij,
>> http://github.com/rkettelerij
>> --
>> View this message in context:
>> http://camel.465427.n5.nabble.com/Enabling-tracing-in-production-tp3243013p3243143.html
>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>
>


--
Willem
----------------------------------
FuseSource
Web: http://www.fusesource.com
Blog:    http://willemjiang.blogspot.com (English)
          http://jnn.javaeye.com (Chinese)
Twitter: willemjiang
Reply | Threaded
Open this post in threaded view
|

Re: Enabling tracing in production

Bengt Rodehav
Thanks Willem - will take a look.

BTW, do you have any hints as to whether it's possible to reconfigure a
tracer "on-the-fly" as I described in an earlier post?

/Bengt


2010/11/1 Willem Jiang <[hidden email]>

> On 10/30/10 4:49 PM, Bengt Rodehav wrote:
>
>> I have a similar situation but I'm not using Spring - I use Java DSL and
>> iPOJO.
>>
>> I have my own tracer that I can publish as an OSGi service using iPOJO. I
>> want to accomplish the following. My other services shall have optional
>> service dependencies to my tracer. This means that if my custom tracer is
>> available then it should be used, otherwise the default tracer should be
>> used.
>>
>> However, just publishing my tracer and requiring it in my other components
>> does not automatically cause Camel to use it. I have to to the following:
>>
>>         getContext().addInterceptStrategy(mTracer);
>>
>>         getContext().setTracing(false);
>>
>>
>> In other words I explicitly set my tracer to be used, I then disable
>> tracing
>> since the first line seems to automatically enable tracing. I then use JMX
>> to enable/disable tracing. I was hoping the above two lines were
>> unnecessary
>> and that merely the existence of a tracer should cause Camel to use it. Is
>> that a Spring specific functionality? I was hoping that any way that an
>> OSGi
>> service was published/consumed would work?
>>
>
> If you take a look at the code of
> AbstractCamelContextFactoryBean.afterPropertiesSet() which is used to set
> the camel context from the sprint configuration, you will find it calls the
> same code.
>
> If you don't want to write upper code twice, you may need to write a
> Factory to create the camel context instance in the same way and look up the
> tracer from the OSGi service registry.
>
> [1]
> https://svn.apache.org/repos/asf/camel/trunk/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBean.java
>
>
>
>> /Bengt
>>
>> 2010/10/30 Richard Kettelerij<[hidden email]>
>>
>>
>>> You don't have to add a Tracer to your Spring context yourself. Camel
>>> adds
>>> one automatically if you have a CamelContext declared in Spring. Also
>>> your
>>> don't have to do anything with the "trace" option in your Spring context.
>>>
>>> I find that the easiest way to enable/disable tracing in production is
>>> through JMX. Just navigate to the CamelContext MBean and modify the
>>> "tracing" attribute. Additionally you can determine what should be traced
>>> by
>>> modifying a few options in the Tracer MBean.
>>>
>>> -----
>>> Richard Kettelerij,
>>> http://github.com/rkettelerij
>>> --
>>> View this message in context:
>>>
>>> http://camel.465427.n5.nabble.com/Enabling-tracing-in-production-tp3243013p3243143.html
>>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>>
>>>
>>
>
> --
> Willem
> ----------------------------------
> FuseSource
> Web: http://www.fusesource.com
> Blog:    http://willemjiang.blogspot.com (English)
>         http://jnn.javaeye.com (Chinese)
> Twitter: willemjiang
>
Reply | Threaded
Open this post in threaded view
|

Re: Enabling tracing in production

Christian Mueller
Administrator
I think this will be a great improvement for Camel 2.6 or Camel 3.0 -
looking up some Camel "components" from the OSGI regestry by default like a
custom tracer, a custom UUID generator, ...
At present, we also configure these component in one OSGI bundle and import
they in every other bundle. Not really smart...

Christian

Am 01.11.2010 13:47 schrieb "Bengt Rodehav" <[hidden email]>:

Thanks Willem - will take a look.

BTW, do you have any hints as to whether it's possible to reconfigure a
tracer "on-the-fly" as I described in an earlier post?

/Bengt


2010/11/1 Willem Jiang <[hidden email]>


> On 10/30/10 4:49 PM, Bengt Rodehav wrote:
>
>> I have a similar situation but I'm not using Sprin...
Reply | Threaded
Open this post in threaded view
|

Re: Enabling tracing in production

huntc
So, back to my original question then...

If I declare the following in my Spring context:

<bean id="camelTracer" class="org.apache.camel.processor.interceptor.Tracer" /> 

...and nothing else at all, then tracing is enabled.

So how do I then turn off tracing for production mode without having to modify my context?

Kind regards,
Christopher
Reply | Threaded
Open this post in threaded view
|

Re: Enabling tracing in production

Christian Mueller
Administrator
Hello Christopher!

If you configure a Tracer in the Camel context, Camel will set tracing to
true.
You can configure the "enabled" property in the Tracer. Camel will only
trace messages, if this property is set to true (the default).

Hope this answers your question,
Christian
Reply | Threaded
Open this post in threaded view
|

Re: Enabling tracing in production

huntc
Hi Christian,

Thanks for your reply.

I was hoping that they'd be a way that I could do it via external configuration. I guess I could create a "trace" property set from my external properties file and have Spring substitute it. However I was hoping that the "-trace" option to the Main class would do something useful. So far, I don't understand its relevance.

Kind regards,
Christopher
Reply | Threaded
Open this post in threaded view
|

Re: Enabling tracing in production

Christian Mueller
Administrator
Hello Christopher,

Yeah, you can use the Spring (or Camel) Property Placeholder mechanism to
externalize this configuration into a property file.
The "-trace" option 'only' enables the tracing functionality. There is no
'-disable-trace' option what is what you need (if you configure a Tracer but
it should not trace anything)...

Cheers,
Christian

On Mon, Nov 1, 2010 at 11:54 PM, huntc <[hidden email]> wrote:

>
> Hi Christian,
>
> Thanks for your reply.
>
> I was hoping that they'd be a way that I could do it via external
> configuration. I guess I could create a "trace" property set from my
> external properties file and have Spring substitute it. However I was
> hoping
> that the "-trace" option to the Main class would do something useful. So
> far, I don't understand its relevance.
>
> Kind regards,
> Christopher
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/Enabling-tracing-in-production-tp3243013p3245917.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
Reply | Threaded
Open this post in threaded view
|

Re: Enabling tracing in production

huntc
Christian Mueller wrote
The "-trace" option 'only' enables the tracing functionality. There is no
'-disable-trace' option what is what you need (if you configure a Tracer but
it should not trace anything)...
Shall I raise an issue on JIRA? I think that the -trace option is completely useless at the moment. I think it should take a boolean argument and always expect that a tracer has been declared. The value of the argument should correspond with enabling the tracer via the context. Furthermore I think that one should always be explicit about tracing. Therefore if there is no trace attribute on the context, you shouldn't get tracing at all i.e. declaring the use of a tracer should involve declaring a tracer and enabling tracing on the context.

What'd think?