Skip to content

Commit

Permalink
LLM experimentation (#7698)
Browse files Browse the repository at this point in the history
## Summary

* adds work in progress script to deploy a llama LLM
* adds some blog posts

## How did you test this change?

[Reflame
preview](https://highlight-landing-git-hig-4285-ai-generate-fb5e34-highlight-run.vercel.app/blog)

[Sitemap](https://highlight-landing-git-hig-4285-ai-generate-fb5e34-highlight-run.vercel.app/sitemap.xml)

## Are there any deployment considerations?

no

## Does this work require review from our design team?

no

---------

Co-authored-by: Jay Khatri <jay@highlight.io>
  • Loading branch information
Vadman97 and jay-khatri committed Feb 22, 2024
1 parent 9307497 commit 8ea4949
Show file tree
Hide file tree
Showing 6 changed files with 537 additions and 1 deletion.
125 changes: 125 additions & 0 deletions blog-content/4-best-logging-libraries-for-java.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
---
title: 'The 4 Best Frameworks for Robust Logging in Java'
createdAt: 2024-02-08T00:00:00.000Z
readingTime: 6
authorFirstName: Vadim
authorLastName: Korolik
authorTitle: CTO @ Highlight
authorTwitter: ''
authorWebsite: ''
authorLinkedIn: 'https://www.linkedin.com/in/vkorolik/'
authorGithub: 'https://github.com/Vadman97'
authorPFP: 'https://www.highlight.io/_next/image?url=https%3A%2F%2Flh3.googleusercontent.com%2Fa-%2FAOh14Gh1k7XsVMGxHMLJZ7qesyddqn1y4EKjfbodEYiY%3Ds96-c&w=3840&q=75'
tags: 'Java, Logging, Development, Programming'
---

## Introduction

In the world of [Java](https://docs.oracle.com/javase/8/docs/technotes/guides/language/index.html) development, logging is more than just a way to record events in your application. It's a vital part of monitoring, debugging, and maintaining healthy software systems. With numerous java logging frameworks available, choosing the right one can significantly impact your application's performance, observability, and troubleshooting capabilities. In this blog post, we will delve into the essential java logging frameworks that every developer should consider to supercharge their logging strategy.

In this article, we'll explore the four best logging libraries for Ruby:

- [Log4j2](https://logging.apache.org/log4j/2.x/)
- [SLF4J](https://www.slf4j.org/)
- [Logback](https://logback.qos.ch/)
- [Java Util Logging (JUL)](https://docs.oracle.com/javase/8/docs/api/java/util/logging/package-summary.html)

## 1. Log4j2 - The Performance Powerhouse

Log4j2 is a well-known successor to the original Log4j framework, offering significant improvements in both performance and flexibility. It's highly adaptable, supporting various output formats and configurable through XML, JSON, and YAML. What sets Log4j2 apart is its asynchronous logging capabilities, which reduce the impact on your application's performance. This feature is especially crucial for high-throughput applications where logging should not become a bottleneck.

Code Snippet Example:

```java
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class MyApp {
private static final Logger logger = LogManager.getLogger(MyApp.class);

public static void main(String[] args) {
logger.info("Hello, Log4j2!");
}
}
```

## 2. SLF4J - The Facade Favorite

Simple Logging Facade for java (SLF4J) serves as a facade or abstraction for various logging frameworks. It allows you to plug in different logging frameworks at deployment time without changing your source code. This flexibility is invaluable when you need to switch between logging frameworks based on different project requirements or when working on multiple projects that use different logging systems.

Code Snippet Example:

```java
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class MyApp {
private static final Logger logger = LoggerFactory.getLogger(MyApp.class);

public static void main(String[] args) {
logger.info("Hello, SLF4J!");
}
}
```

The project `pom.xml` would define the logger that SLF4J is using to process the data. With no code changes, you can set the logger binding to
any library that will act as the backend for the log data.

```XML
<!-- SLF4J API -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.30</version>
</dependency>
<!-- logback binding -->
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.3</version>
</dependency>
```

<BlogCallToAction/>

## 3. Logback - The Rising Star

Logback is considered the successor to Log4j and offers several advantages, including faster performance, more concise configuration, and out-of-the-box support for JSON, XML, and HTML formats. It integrates seamlessly with SLF4J, providing a robust logging solution. Logback is an excellent choice for developers looking for a modern, efficient, and flexible logging framework.

Code Snippet Example:

```java
import ch.qos.logback.classic.Logger;
import org.slf4j.LoggerFactory;

public class MyApp {
private static final Logger logger = (Logger) LoggerFactory.getLogger(MyApp.class);

public static void main(String[] args) {
logger.info("Hello, Logback!");
}
}
```

## 4. JUL (java Util Logging) - The Built-in Solution

java Util Logging (JUL), included in the JDK, is a straightforward and accessible logging option for applications that don't require the complexity of external frameworks. While it may lack some advanced features of dedicated logging frameworks, JUL is a solid choice for simple applications or where minimizing external dependencies is a priority.

Code Snippet Example:

```java
import java.util.logging.Logger;

public class MyApp {
private static final Logger logger = Logger.getLogger(MyApp.class.getName());

public static void main(String[] args) {
logger.info("Hello, java Util Logging!");
}
}
```

## Conclusion

Choosing the right java logging framework depends on your specific needs, such as performance requirements, configuration flexibility, and integration capabilities. Whether it's the robust Log4j2, the versatile SLF4J, the efficient Logback, or the straightforward JUL, each framework offers unique features that can enhance your application's logging. Remember, effective logging is crucial for application health, debugging, and performance monitoring. Select the framework that aligns best with your goals to ensure a smooth and insightful development experience.

226 changes: 226 additions & 0 deletions blog-content/application-tracing-in-dot-net.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,226 @@
---
title: 'Application Tracing in .NET for Performance Monitoring'
createdAt: 2024-02-10T00:00:00.000Z
readingTime: 8
authorFirstName: Vadim
authorLastName: Korolik
authorTitle: CTO @ Highlight
authorTwitter: ''
authorWebsite: ''
authorLinkedIn: 'https://www.linkedin.com/in/vkorolik/'
authorGithub: 'https://github.com/Vadman97'
authorPFP: 'https://www.highlight.io/_next/image?url=https%3A%2F%2Flh3.googleusercontent.com%2Fa-%2FAOh14Gh1k7XsVMGxHMLJZ7qesyddqn1y4EKjfbodEYiY%3Ds96-c&w=3840&q=75'
tags: '.NET, Logging, Development, Programming'
---

## Introduction
Application tracing is a critical aspect of software development and maintenance, especially in complex .NET environments. It involves monitoring and recording application activities, providing insights into application behavior and performance. This guide will delve into the essential tools and techniques for effective application tracing in .NET, ensuring that developers and administrators can efficiently troubleshoot and optimize their applications.

## The Role of Tracing in .NET Applications
In .NET, application tracing provides a window into the running state of applications, helping identify bottlenecks, errors, and performance issues. It's not only about finding problems; tracing also offers valuable data for optimizing and refining application functionality.

## Utilizing Built-in .NET Tracing Capabilities
.NET Framework and .NET Core offer built-in tracing capabilities that are robust and easy to implement. Let’s explore a basic example of how to implement tracing in a .NET application:

```java
using System.Diagnostics;

Trace.Listeners.Add(new TextWriterTraceListener("logfile.log"));
Trace.AutoFlush = true;
Trace.WriteLine("Starting application tracing");

// Your application logic here

Trace.WriteLine("Ending application tracing");
```
This code snippet demonstrates how to set up a simple trace listener that writes trace output to a file. This is fundamental for any .NET application requiring basic logging and tracing capabilities.

## Advanced Tracing with DiagnosticSource in .NET Core
For more advanced scenarios, especially in .NET Core, System.Diagnostics.DiagnosticSource provides a powerful way to collect rich telemetry data. Here's an example:

```java
using System.Diagnostics;

var source = new DiagnosticListener("MyApplicationSource");

if (source.IsEnabled("StartRequest"))
{
source.Write("StartRequest", new { RequestId = Guid.NewGuid(), Timestamp = DateTime.UtcNow });
}

// Application logic here

if (source.IsEnabled("EndRequest"))
{
source.Write("EndRequest", new { RequestId = Guid.NewGuid(), Timestamp = DateTime.UtcNow });
}
```
This code creates a DiagnosticListener that emits custom events, making it a versatile tool for complex tracing requirements.

## Leveraging Third-Party Tools for Tracing
### Application Insights for Comprehensive Telemetry
Application Insights, a feature of Azure Monitor, is an extensible Application Performance Management (APM) service for developers. It can be easily integrated into .NET applications:

```java
using Microsoft.ApplicationInsights;
using Microsoft.ApplicationInsights.Extensibility;

var telemetryConfiguration = TelemetryConfiguration.CreateDefault();
telemetryConfiguration.InstrumentationKey = "your_instrumentation_key_here";
var telemetryClient = new TelemetryClient(telemetryConfiguration);

telemetryClient.TrackTrace("Application trace message");
```
This snippet shows how to send trace messages to Application Insights, which provides analytics and actionable insights on application performance and usage.

### Highlight.io for Open Source Telemetry via OpenTelemetry

Setting up OpenTelemetry tracing for a .NET application involves a few key steps. OpenTelemetry is a set of APIs, libraries, agents, and instrumentation that allow you to create and manage telemetry data (metrics, logs, and traces) for your applications. Here's how you can set up tracing in a .NET application:
1. Install Necessary NuGet Packages
First, you need to add the OpenTelemetry packages to your project. You can do this via the NuGet package manager. The primary package you'll need is OpenTelemetry. Depending on the specific needs of your application, you may also need exporters (like Zipkin, Jaeger, etc.) and instrumentation for specific libraries.

```bash
# Copy code
dotnet add package OpenTelemetry
dotnet add package OpenTelemetry.Exporter.Console
dotnet add package OpenTelemetry.Exporter.OpenTelemetryProtocol
dotnet add package OpenTelemetry.Instrumentation.AspNetCore
```

2. Configure Services in Startup.cs

In the Startup.cs file of your .NET application, you need to configure the OpenTelemetry services. This includes setting up the tracing pipeline with any necessary exporters and instrumentations.

Here is an example code block for setting up a basic OpenTelemetry tracing with a console exporter and ASP.NET Core instrumentation:

```java
using OpenTelemetry.Trace;

public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
// Other service configurations ...

// Configure OpenTelemetry Tracing
services.AddOpenTelemetryTracing(builder =>
{
builder
.AddAspNetCoreInstrumentation()
.AddConsoleExporter(); // Using console exporter for demonstration
});
}

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
// Existing configuration code...

// Ensure to use the appropriate middleware if needed
app.UseOpenTelemetry();
}
}
```

3. Instrumenting Your Code

To create custom traces or to add additional information to the automatic traces, you can use the OpenTelemetry API in your application code:

```java
using System.Diagnostics;
using OpenTelemetry.Trace;

public class MyService
{
private static readonly ActivitySource ActivitySource = new ActivitySource("MyService");

public void DoWork()
{
using (var activity = ActivitySource.StartActivity("DoingWork"))
{
// Your logic here
// You can add custom tags or events to 'activity' as needed
}
}
}
```

The configuration and code above set up a basic tracing pipeline for a .NET application. This will set up a console exporter to debug traces to the console log, but you can change to an OTLP exporter to send traces to a remote collector.

4. Update the code block to send traces to highlight

```java
using OpenTelemetry.Trace;

public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
// Other service configurations ...

var resourceBuilder = ResourceBuilder.CreateDefault()
.AddService("YourServiceName", serviceVersion: "1.0.0")
.AddAttributes(new Dictionary<string, object>
{
{ "environment", "production" },
// Add other attributes as needed
});


// Configure OpenTelemetry Tracing with OTLP over HTTP
services.AddOpenTelemetryTracing(builder =>
{
builder
.SetResourceBuilder(resourceBuilder)
.AddAspNetCoreInstrumentation()
.AddOtlpExporter(options =>
{
options.Endpoint = new Uri("https://otel.highlight.io:4318");
options.Protocol = OpenTelemetry.Exporter.OtlpExportProtocol.HttpProtobuf;

// Optional: Customize batching behavior
options.BatchExportProcessorOptions = new OpenTelemetry.BatchExportProcessorOptions<Activity>
{
MaxQueueSize = 2048,
ScheduledDelayMilliseconds = 5000,
ExporterTimeoutMilliseconds = 30000,
MaxExportBatchSize = 512
};
});
});
}

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
// Existing configuration code...

// Ensure to use the appropriate middleware if needed
app.UseOpenTelemetry();
}
}
```

Get started today with our [OpenTelemetry instrumentation](https://opentelemetry.io/docs/languages/net/) for .NET that gives you flexibility with your data destination.

<BlogCallToAction/>

### NLog for Flexible and Structured Logging
NLog is a versatile logging tool for .NET, allowing for structured logging, which is crucial in modern application tracing. Here's a basic setup:
```java
var config = new NLog.Config.LoggingConfiguration();
var logfile = new NLog.Targets.FileTarget("logfile") { FileName = "file.txt" };
var logconsole = new NLog.Targets.ConsoleTarget("logconsole");
config.AddRule(LogLevel.Info, LogLevel.Fatal, logconsole);
config.AddRule(LogLevel.Debug, LogLevel.Fatal, logfile);
NLog.LogManager.Configuration = config;
```
This configuration sets up NLog to log messages to both a file and the console, providing a flexible approach to logging.
## Conclusion
Effective tracing in .NET applications is key to understanding and improving application behavior and performance. This guide has introduced various tools and techniques, from basic built-in .NET tracing to advanced tools like Application Insights and NLog. By choosing the right combination of these tools, developers can gain valuable insights and maintain robust, high-performance applications.
Explore these tracing techniques in your .NET projects. Share your experiences and insights in the comments below. For more in-depth information, check out our additional resources.
Loading

0 comments on commit 8ea4949

Please sign in to comment.