ApplicationInsights-Java
ApplicationInsights-Java copied to clipboard
Document/Sample project for new 3.x applications
Is your feature request related to a problem? Please describe. When creating a new application I notice that there are a lot of configurations needed for the following elements:
- Span creation
- Structured logging
- Configuration of Logback/other logging
Describe the solution you would like I would like to see in the wiki or a somewhere in the code a sample application that I could follow and run to see it in action.
Describe alternatives you have considered Wiki/Sample project
Additional context Currently I'm working for an application and notice that the documentation is not filling my needs. A startup/guide and/of sample project would greatly help.
hi @deman-Innotractor! the reason we don't provide a specific sample application, is that the javaagent will work with any sample application.
do you have a specific issue you are having, maybe we can help you with that?
Hi @trask, sorry for the mess of text below. Currently we have accepted the current situation but if we can improve on this, that will be great. If needed I could try and make some examples projects for the points.
At the time I needed it to combine the right OperationId (that another application generated) and noticed that it only accepted a shorter version.
An other problem was that structured logging was (and still is) not working for me. I'm not sure if the problem is a Azure "Application Insights" problem, or that it was somewhere else. I was thinking it was dependent on some structural logging framework, and decided then that it took too much time to get it working and dropped it then.
In that time I was also struggling to get it all working as needed. The points that I was confused was:
- Is there a mode that I can log to a local logging sink, and how so.
- Can I resume a OperationID if I set this? And how does it work.
- Is structured logging supported at all? Or just to Azure DevOps not?
- How can I make my custom "Autocollected dependencies".
- How can I make use of the "metrics" call
public final Flux<T> metrics()
- How can I use 'GlobalOpenTelemetry' in combination with Azure.
Below this is some sample (c# vs java logging) differences (using java:3.3.1): Java id: b7f741da59477e80 C# id: 34b999035fed46388a25cade91dc3d51
Java operation_Id: f76809c8ed1581827a2848fcca879ca2 C# operation_Id: 23352843fc222d48871282685216fd1e
Java operation_ParentId: f76809c8ed1581827a2848fcca879ca2 C# operation_ParentId: fabf3312ab26d744
Below is some code that I tried to make some of those questions work. Note: this was just to get some tests in.
var tr = GlobalOpenTelemetry.get().getTracer("tracer");
var span = tr.spanBuilder("spanBuilder")
.setSpanKind(SpanKind.CLIENT)
//.setParent(Context.current().with(Span.current()))
.startSpan();
span.end();
var id = "eeeedddddddddddd";
var traceID = "0000000000000000" + id; //TraceId.fromLongs(0, 13); //Operation_Id
var res = TraceId.isValid(traceID);
var spanId = id; //parent-id
var parent = SpanContext.create(traceID, spanId, TraceFlags.getSampled(), TraceState.getDefault());
if (!parent.isValid()){
return;
}
var context = Context.current().with(Span.wrap(parent));
var span = tr.spanBuilder("invalid spanId")
.setParent(context)
.startSpan();
try(Scope scope = span.makeCurrent()) {
Span childSpan = tr.spanBuilder("child").startSpan();
childSpan.recordException(new IllegalArgumentException("Test"));
childSpan.end();
} finally {
span.end();
}
int i = 0;
while (true){
if (i++ > 10000){
return;
}
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
hi @deman-Innotractor!
- Is there a mode that I can log to a local logging sink, and how so.
I didn't follow this, can you explain a bit more?
- Can I resume a OperationID if I set this? And how does it work.
I added an example for this in our new Samples repo: https://github.com/Azure-Samples/ApplicationInsights-Java-Samples/tree/main/advanced/manual-trace-propagation
- Is structured logging supported at all? Or just to Azure DevOps not?
I updated the docs to explicitly mention structured logging: https://learn.microsoft.com/en-us/azure/azure-monitor/app/java-in-process-agent#send-custom-traces-and-exceptions-by-using-your-favorite-logging-framework:~:text=configuration%20options.-,Structured%20logging,-(attaching%20custom%20dimensions
- How can I make my custom "Autocollected dependencies".
Can you explain this a bit more also?
- How can I make use of the "metrics" call public final Flux<T> metrics()
Can you explain this a bit more too? i'm not sure what this metrics() method refers to
- How can I use 'GlobalOpenTelemetry' in combination with Azure.
I updated the docs to add this: https://learn.microsoft.com/en-us/azure/azure-monitor/app/java-in-process-agent#add-spans-using-the-opentelemetry-api
This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 7 days. It will be closed if no further activity occurs within 7 days of this comment.
This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 7 days. It will be closed if no further activity occurs within 7 days of this comment.
This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 7 days. It will be closed if no further activity occurs within 7 days of this comment.