Coverage Report

Created: 2026-03-22 07:09

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/fluent-bit/plugins/in_opentelemetry/opentelemetry_config.c
Line
Count
Source
1
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3
/*  Fluent Bit
4
 *  ==========
5
 *  Copyright (C) 2015-2026 The Fluent Bit Authors
6
 *
7
 *  Licensed under the Apache License, Version 2.0 (the "License");
8
 *  you may not use this file except in compliance with the License.
9
 *  You may obtain a copy of the License at
10
 *
11
 *      http://www.apache.org/licenses/LICENSE-2.0
12
 *
13
 *  Unless required by applicable law or agreed to in writing, software
14
 *  distributed under the License is distributed on an "AS IS" BASIS,
15
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
 *  See the License for the specific language governing permissions and
17
 *  limitations under the License.
18
 */
19
20
#include <fluent-bit/flb_input_plugin.h>
21
#include <fluent-bit/flb_oauth2_jwt.h>
22
#include "opentelemetry.h"
23
24
/* default HTTP port for OTLP/HTTP is 4318 */
25
0
#define OTLP_HTTP_PORT    4318
26
27
struct flb_opentelemetry *opentelemetry_config_create(struct flb_input_instance *ins)
28
0
{
29
0
    int ret;
30
0
    char port[8];
31
0
    struct flb_opentelemetry *ctx;
32
33
0
    ctx = flb_calloc(1, sizeof(struct flb_opentelemetry));
34
0
    if (!ctx) {
35
0
        flb_errno();
36
0
        return NULL;
37
0
    }
38
0
    ctx->ins = ins;
39
0
    ctx->oauth2_cfg.jwks_refresh_interval = 300;
40
41
    /* Load the config map */
42
0
    ret = flb_input_config_map_set(ins, (void *) ctx);
43
0
    if (ret == -1) {
44
0
        flb_free(ctx);
45
0
        return NULL;
46
0
    }
47
48
0
    if (ins->oauth2_jwt_config_map && mk_list_size(&ins->oauth2_jwt_properties) > 0) {
49
0
        ret = flb_config_map_set(&ins->oauth2_jwt_properties,
50
0
                                 ins->oauth2_jwt_config_map,
51
0
                                 &ctx->oauth2_cfg);
52
0
        if (ret == -1) {
53
0
            flb_free(ctx);
54
0
            return NULL;
55
0
        }
56
0
    }
57
58
    /* Listen interface (if not set, defaults to 0.0.0.0:4318) */
59
0
    flb_input_net_default_listener("0.0.0.0", OTLP_HTTP_PORT, ins);
60
61
0
    ctx->listen = flb_strdup(ins->host.listen);
62
0
    snprintf(port, sizeof(port) - 1, "%d", ins->host.port);
63
0
    ctx->tcp_port = flb_strdup(port);
64
65
0
    return ctx;
66
0
}
67
68
int opentelemetry_config_destroy(struct flb_opentelemetry *ctx)
69
0
{
70
0
    flb_http_server_destroy(&ctx->http_server);
71
72
0
    if (ctx->oauth2_ctx) {
73
0
        flb_oauth2_jwt_context_destroy(ctx->oauth2_ctx);
74
0
        ctx->oauth2_ctx = NULL;
75
0
    }
76
77
0
    flb_free(ctx->listen);
78
0
    flb_free(ctx->tcp_port);
79
0
    flb_free(ctx);
80
81
0
    return 0;
82
0
}