@@ -40,6 +40,7 @@ struct flb_out_datadog *flb_datadog_conf_create(struct flb_output_instance *ins,
4040 char * host = NULL ;
4141 char * port = NULL ;
4242 char * uri = NULL ;
43+ char * site = NULL ;
4344
4445 /* Start resource creation */
4546 ctx = flb_calloc (1 , sizeof (struct flb_out_datadog ));
@@ -98,6 +99,15 @@ struct flb_out_datadog *flb_datadog_conf_create(struct flb_output_instance *ins,
9899 return NULL ;
99100 }
100101
102+ /* Parse site parameter early so it's available for host construction */
103+ tmp = flb_output_get_property ("site" , ins );
104+ if (tmp ){
105+ ctx -> site = flb_sds_create (tmp );
106+ flb_plg_debug (ctx -> ins , "site parameter set to: %s" , ctx -> site );
107+ } else {
108+ flb_plg_debug (ctx -> ins , "no site parameter found" );
109+ }
110+
101111 /* Tag Key */
102112 if (ctx -> include_tag_key == FLB_TRUE ) {
103113 ctx -> nb_additional_entries ++ ;
@@ -126,7 +136,7 @@ struct flb_out_datadog *flb_datadog_conf_create(struct flb_output_instance *ins,
126136 tmp = flb_output_get_property ("provider" , ins );
127137 ctx -> remap = tmp && (strlen (tmp ) == strlen (FLB_DATADOG_REMAP_PROVIDER )) && \
128138 (strncmp (tmp , FLB_DATADOG_REMAP_PROVIDER , strlen (tmp )) == 0 );
129-
139+
130140 ctx -> uri = flb_sds_create ("/api/v2/logs" );
131141 if (!ctx -> uri ) {
132142 flb_plg_error (ctx -> ins , "error on uri generation" );
@@ -138,18 +148,47 @@ struct flb_out_datadog *flb_datadog_conf_create(struct flb_output_instance *ins,
138148
139149 /* Get network configuration */
140150 if (!ins -> host .name ) {
141- tmp_sds = flb_sds_create (FLB_DATADOG_DEFAULT_HOST );
151+ /* No explicit Host parameter, check for site */
152+ if (ctx -> site ) {
153+ flb_plg_debug (ctx -> ins , "using site for host construction: %s" , ctx -> site );
154+ /* Construct hostname from site */
155+ tmp_sds = flb_sds_create ("http-intake.logs." );
156+ if (!tmp_sds ) {
157+ flb_errno ();
158+ flb_datadog_conf_destroy (ctx );
159+ return NULL ;
160+ }
161+ flb_plg_debug (ctx -> ins , "created base hostname: %s" , tmp_sds );
162+ flb_plg_debug (ctx -> ins , "about to concatenate site: %s (length: %zu)" , ctx -> site , flb_sds_len (ctx -> site ));
163+ tmp_sds = flb_sds_cat (tmp_sds , (const char * )ctx -> site , flb_sds_len (ctx -> site ));
164+ flb_plg_debug (ctx -> ins , "after concatenation: %s" , tmp_sds );
165+ ctx -> host = tmp_sds ;
166+ flb_plg_debug (ctx -> ins , "host constructed from site: %s" , ctx -> host );
167+ } else {
168+ flb_plg_debug (ctx -> ins , "no site specified, using default host" );
169+ /* No site specified, use default */
170+ tmp_sds = flb_sds_create (FLB_DATADOG_DEFAULT_HOST );
171+ if (!tmp_sds ) {
172+ flb_errno ();
173+ flb_datadog_conf_destroy (ctx );
174+ return NULL ;
175+ }
176+ ctx -> host = tmp_sds ;
177+ flb_plg_debug (ctx -> ins , "host: %s" , ctx -> host );
178+ }
142179 }
143180 else {
181+ flb_plg_debug (ctx -> ins , "explicit Host parameter takes precedence: %s" , ins -> host .name );
182+ /* Explicit Host parameter takes precedence */
144183 tmp_sds = flb_sds_create (ins -> host .name );
184+ if (!tmp_sds ) {
185+ flb_errno ();
186+ flb_datadog_conf_destroy (ctx );
187+ return NULL ;
188+ }
189+ ctx -> host = tmp_sds ;
190+ flb_plg_debug (ctx -> ins , "host: %s" , ctx -> host );
145191 }
146- if (!tmp_sds ) {
147- flb_errno ();
148- flb_datadog_conf_destroy (ctx );
149- return NULL ;
150- }
151- ctx -> host = tmp_sds ;
152- flb_plg_debug (ctx -> ins , "host: %s" , ctx -> host );
153192
154193 if (ins -> host .port != 0 ) {
155194 ctx -> port = ins -> host .port ;
@@ -222,6 +261,9 @@ int flb_datadog_conf_destroy(struct flb_out_datadog *ctx)
222261 if (ctx -> upstream ) {
223262 flb_upstream_destroy (ctx -> upstream );
224263 }
264+ if (ctx -> site ){
265+ flb_sds_destroy (ctx -> site );
266+ }
225267 flb_free (ctx );
226268
227269 return 0 ;
0 commit comments