Trace API support in ADO.NET provider for Firebird (FbTrace)
When I came from Firebird Conference in Bremen I was so excited about all the people being excited about Trace and Audit API
I decided I’ll implement this in .NET provider as soon as possible. And here it is.
Right now there’s a new class (and few supporting it) on FirebirdSql.Data.Services namespace called FbTrace, that you can use to start trace session and see what’s going on on server. I’ll not describe the Trace API itself, you can find info in documentation, I’ll rather focus on how you can use it from the provider.
Right now, as I have no sharp idea how the people will use it, I implemented it simply and later, if I find some common cases, I’ll add some “shortcuts” to help with these scenarios.
If you have ever used any FbService derived class, you’ll be able to use FbTrace in under a minute.
FbTrace trace = new FbTrace();
trace.ConnectionString = "database=localhost:rrr.fdb;user=sysdba;password=masterkey";
trace.ServiceOutput += (object sender, ServiceOutputEventArgs e) =>
{
Console.WriteLine(e.Message);
};
trace.DatabasesConfigurations.Add(
new FbDatabaseTraceConfiguration()
{
DatabaseName = string.Empty,
Enabled = true,
Events = FbDatabaseTraceEvents.Connections | FbDatabaseTraceEvents.Transactions
});
trace.Start("test");
The important stuff is in FbDatabaseTraceConfiguration class, where you specify what should be traced, exactly the same way as in fbtrace.conf (you can find this file in Firebird‘s installation). Mainly the database name to match for trace (if you want only some), whether it’s enabled (probably useful if you want to keep the configuration somewhere, but selectively turn it off and on). And finally the events you’re interested in – FbDatabaseTraceEvents enum. In the example above I’m tracing only connections and transactions (not for example stored procedures prepares or executions). All this configuration is added into DatabasesConfigurations property. You can have for sure different configurations for different databases. For Services API tracing there’s property, because it’s only one “services instance” in Firebird server, called ServiceConfiguration. At the last line I’m starting the trace session named test using method Start.
And that’s it. When something happens in the database the ServiceOutput event handler will be invoked and you’ll get the trace message.
Of course, you can also call Suspend, Stop, Resume and List methods to do accordant actions in API.
This is the initial implementation and some methods may be added (I’m already thinking about a few). Hope you enjoy it. Feel free to play with it and comment here or in list.



There's 6 Comments So Far
December 14th, 2010 at 23:55
Nice to see, that you adopt the Trace API stuff in the .NET provider.
December 15th, 2010 at 18:48
Hi great job! Have you thought about a class to trace and audit directly to database’s table.
In my fb2.5 I would like to audit all changes (I,U,D) made to every table in my fdb writing to audit_table the following info :
table name, field name, old value, new value, user, action type (Insert,Update,Delete)
I know I could solve it creating a single trigger for every table..is there a simpler way ?
What about it ? Thanx
December 15th, 2010 at 19:11
I don’t think the Trace API was designed for this. Your application would need to be constantly running and parsing the result.
December 16th, 2010 at 10:56
Yes, you’re right. Just an idea.You say “some methods may be added”… Well, just think about auditing changes.It would be a great improvement Thank you from Italy!
Who Linked To This Post?
Share your thoughts, leave a comment!